-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to Jakarta Equivalents (#959)
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 4. Legacy tests were deleted because keeping the versions pinned to the correct transitives was an exercise in futility.
- Loading branch information
Showing
22 changed files
with
759 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
55 changes: 55 additions & 0 deletions
55
tracing-jaxrs-jakarta/src/main/java/com/palantir/tracing/jaxrs/JaxRsTracers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
tracing-jaxrs-jakarta/src/test/java/com/palantir/tracing/jaxrs/JaxRsTracersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
Oops, something went wrong.