Skip to content

Commit

Permalink
Migrate to Jakarta Equivalents (#959)
Browse files Browse the repository at this point in the history
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
mglazer authored Aug 9, 2022
1 parent a4f68c3 commit 8566954
Show file tree
Hide file tree
Showing 22 changed files with 759 additions and 201 deletions.
12 changes: 12 additions & 0 deletions changelog/@unreleased/pr-959.v2.yml
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
10 changes: 7 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ 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'

include 'tracing-servlet'
include 'tracing-jaxrs'
include 'tracing-jersey'
include 'tracing-servlet-jakarta'
include 'tracing-jaxrs-jakarta'
include 'tracing-jersey-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 {

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"

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 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"
}
Loading

0 comments on commit 8566954

Please sign in to comment.