-
Notifications
You must be signed in to change notification settings - Fork 19
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
Changes from 7 commits
80f0c8e
8daf88e
d869333
3bbebfc
5a1f078
761a5dd
2f37933
6eb7780
1b55aa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type: improvement | ||
improvement: | ||
description: |- | ||
Introduced jakarta equivalents of all modules which had a javax dependency | ||
|
||
Additionally had to do a few things: | ||
|
||
1. Migrated from spotify's ADT to derive4j which generates types without a legacy javax.annotation.Generated type | ||
2. Fixed a few tests | ||
3. Upgraded newer libraries to Junit5 | ||
links: | ||
- https://github.com/palantir/tracing-java/pull/959 |
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 { | ||
|
||
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()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I follow up a commit to deprecate everything? I still have at least 6 other libraries that have to migrate first before I could even provide an alternative for someone to migrate to. |
||
|
||
testImplementation "ch.qos.logback:logback-classic" | ||
testImplementation "junit:junit" | ||
|
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 project(":tracing") | ||
|
||
implementation "org.glassfish.jersey.core:jersey-server" | ||
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" | ||
} |
There was a problem hiding this comment.
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 totracing-jaxrs-jakarta
and we'll deprecate/remove the non-Jakarta implementations in a future major breaking release, right?There was a problem hiding this comment.
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?