Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Jakarta Equivalents #959

Merged
merged 9 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ apply plugin: 'com.palantir.baseline'
apply plugin: 'com.palantir.consistent-versions'
apply plugin: 'com.palantir.baseline-java-versions'
apply plugin: 'com.palantir.jdks.latest'
apply plugin: 'com.palantir.consistent-versions'
mglazer marked this conversation as resolved.
Show resolved Hide resolved

repositories {
mavenCentral() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } }
Expand Down
14 changes: 10 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ include 'tracing'
include 'tracing-api'
include 'tracing-benchmarks'
include 'tracing-demos'
include 'tracing-jaxrs'
include 'tracing-jersey'
include 'tracing-okhttp3'
include 'tracing-servlet'
include 'tracing-test-utils'
include 'tracing-undertow'

withJakarta('tracing-servlet')
withJakarta('tracing-undertow')
mglazer marked this conversation as resolved.
Show resolved Hide resolved
withJakarta('tracing-jaxrs')
withJakarta('tracing-jersey')

def withJakarta(name) {
include name
include "${name}-jakarta"
}
31 changes: 31 additions & 0 deletions tracing-jaxrs-jakarta/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'org.inferred.processors'

apply plugin: 'com.palantir.external-publish-jar'
apply plugin: 'com.palantir.revapi'

dependencies {
api project(":tracing")
api "jakarta.ws.rs:jakarta.ws.rs-api"

testImplementation "ch.qos.logback:logback-classic"
testImplementation "junit:junit"
testImplementation "org.assertj:assertj-core"
testImplementation "org.jmock:jmock"
testImplementation "org.mockito:mockito-core"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.tracing.jaxrs;

import com.palantir.tracing.CloseableSpan;
import com.palantir.tracing.Detached;
import com.palantir.tracing.DetachedSpan;
import com.palantir.tracing.Tracers;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.StreamingOutput;
import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.Callable;

public final class JaxRsTracers {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming anything currently using tracing-jaxrs should migrate to tracing-jaxrs-jakarta and we'll deprecate/remove the non-Jakarta implementations in a future major breaking release, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of? Generally, people should migrate as gradually more and more things will start breaking, to the point that eventually we can retire the legacy versions of these. But until that happens across all libraries, we can't really say: You should do this.

Does that make sense?


private JaxRsTracers() {}

/** Like {@link Tracers#wrap(Callable)}, but for StreamingOutputs. */
public static StreamingOutput wrap(StreamingOutput delegate) {
return new TracingAwareStreamingOutput(delegate);
}

private static class TracingAwareStreamingOutput implements StreamingOutput {

private final StreamingOutput delegate;
private final Detached detached;

TracingAwareStreamingOutput(StreamingOutput delegate) {
this.delegate = delegate;
this.detached = DetachedSpan.detach();
}

@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
try (CloseableSpan ignored = detached.childSpan("streaming-output")) {
delegate.write(output);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.tracing.jaxrs;

import static org.assertj.core.api.Assertions.assertThat;

import com.palantir.tracing.AlwaysSampler;
import com.palantir.tracing.Tracer;
import jakarta.ws.rs.core.StreamingOutput;
import java.io.ByteArrayOutputStream;
import org.junit.Test;

public final class JaxRsTracersTest {

@Test
public void testWrappingStreamingOutput_streamingOutputTraceIsIsolated_sampled() throws Exception {
Tracer.setSampler(AlwaysSampler.INSTANCE);
Tracer.getAndClearTrace();

Tracer.fastStartSpan("outside");
StreamingOutput streamingOutput = JaxRsTracers.wrap(_os -> {
Tracer.fastStartSpan("inside"); // never completed
});
streamingOutput.write(new ByteArrayOutputStream());
assertThat(Tracer.completeSpan().get().getOperation()).isEqualTo("outside");
}

@Test
public void testWrappingStreamingOutput_streamingOutputTraceIsIsolated_unsampled() throws Exception {
Tracer.setSampler(() -> false);
Tracer.getAndClearTrace();

Tracer.fastStartSpan("outside");
StreamingOutput streamingOutput = JaxRsTracers.wrap(_os -> {
Tracer.fastStartSpan("inside"); // never completed
});
streamingOutput.write(new ByteArrayOutputStream());
assertThat(Tracer.hasTraceId()).isTrue();
Tracer.fastCompleteSpan();
assertThat(Tracer.hasTraceId()).isFalse();
}

@Test
public void testWrappingStreamingOutput_traceStateIsCapturedAtConstructionTime_sampled() throws Exception {
Tracer.setSampler(AlwaysSampler.INSTANCE);
Tracer.getAndClearTrace();

Tracer.fastStartSpan("before-construction");
StreamingOutput streamingOutput = JaxRsTracers.wrap(_os -> {
assertThat(Tracer.completeSpan().get().getOperation()).isEqualTo("streaming-output");
});
Tracer.fastStartSpan("after-construction");
streamingOutput.write(new ByteArrayOutputStream());
}

@Test
public void testWrappingStreamingOutput_traceStateIsCapturedAtConstructionTime_unsampled() throws Exception {
Tracer.setSampler(() -> false);
Tracer.getAndClearTrace();

Tracer.fastStartSpan("before-construction");
StreamingOutput streamingOutput = JaxRsTracers.wrap(_os -> {
assertThat(Tracer.hasTraceId()).isTrue();
Tracer.fastCompleteSpan();
assertThat(Tracer.hasTraceId()).isFalse();
});
Tracer.fastStartSpan("after-construction");
streamingOutput.write(new ByteArrayOutputStream());
}
}
6 changes: 5 additions & 1 deletion tracing-jaxrs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ apply plugin: 'org.inferred.processors'
apply plugin: 'com.palantir.external-publish-jar'
apply plugin: 'com.palantir.revapi'

versionsLock {
disableJavaPluginDefaults()
}

dependencies {
api project(":tracing")
api "jakarta.ws.rs:jakarta.ws.rs-api"
api "javax.ws.rs:javax.ws.rs-api:2.1.1"
mglazer marked this conversation as resolved.
Show resolved Hide resolved

testImplementation "ch.qos.logback:logback-classic"
testImplementation "junit:junit"
Expand Down
34 changes: 34 additions & 0 deletions tracing-jersey-jakarta/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* (c) Copyright 2018 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'com.palantir.external-publish-jar'
apply plugin: 'com.palantir.revapi'

dependencies {
api "org.glassfish.jersey.core:jersey-server"
mglazer marked this conversation as resolved.
Show resolved Hide resolved
api project(":tracing")

implementation 'com.google.guava:guava'
implementation 'jakarta.ws.rs:jakarta.ws.rs-api'
implementation project(':tracing-api')

testImplementation "io.dropwizard:dropwizard-testing"
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.assertj:assertj-core"
testImplementation "org.hamcrest:hamcrest-all"
testImplementation "org.mockito:mockito-core"
testImplementation "org.mockito:mockito-junit-jupiter"
}
Loading