Skip to content

Addresses opencensus-shim integration#6875

Closed
dmarkwat wants to merge 5 commits intoopen-telemetry:mainfrom
dmarkwat:opencensus-shim
Closed

Addresses opencensus-shim integration#6875
dmarkwat wants to merge 5 commits intoopen-telemetry:mainfrom
dmarkwat:opencensus-shim

Conversation

@dmarkwat
Copy link
Copy Markdown
Contributor

@dmarkwat dmarkwat commented Oct 14, 2022

Addresses observed opencensus-shim breakage when the otel java agent is instrumenting an application which uses opencensus and the shim necessary to bridge it with otel.

Associated issue: #6876

I needed to do this in-tree as there was seemingly no other way to obtain the otel-shaded jar.

@dmarkwat dmarkwat requested a review from a team October 14, 2022 02:13
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Oct 14, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@dmarkwat
Copy link
Copy Markdown
Contributor Author

(Signed CLA)

@github-actions github-actions Bot requested a review from theletterf October 22, 2022 16:30
@trask
Copy link
Copy Markdown
Member

trask commented Oct 22, 2022

hi @dmarkwat! it looks like some unrelated commits got pulled into your PR, can you try rebasing to see if that cleans them up?

@dmarkwat
Copy link
Copy Markdown
Contributor Author

@trask , yeah I'm not sure what happened there; I think I merged instead of rebased. Does it look good now?

@trask
Copy link
Copy Markdown
Member

trask commented Oct 22, 2022

@trask , yeah I'm not sure what happened there; I think I merged instead of rebased. Does it look good now?

yup 👍

Copy link
Copy Markdown
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

nice work diving into the deep end, this is some tricky stuff!

I left some preliminary suggestions on structure / conventions, and after you have a chance to review, then I'll try to dive into the deep end also and review the trickier stuff

Comment thread settings.gradle.kts
include(":instrumentation:wicket-8.0:javaagent")

include(":instrumentation:opencensus-shim:javaagent")
include(":instrumentation:opencensus-shim:testing")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

since there will only ever be javaagent module for this, you can merge the test code into the javaagent module and remove the testing module

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, but is there a way to test the "regression" test (should be renamed baseline maybe?) as a library? I didn't see a way to run some tests against the library plugin (id("otel.library-instrumentation")) and some against the javaagent plugin (id("otel.javaagent-instrumentation")) in the same module.

// doesn't provide a version
// for (List<SpanData> trace : completeTraces) {
// for (SpanData span : trace) {
// if (!span.getInstrumentationScopeInfo().getName().equals("test")) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

by naming the tracer test above, this assertion should no longer fail

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah gotcha you're absolutely right. But, I just tried that but I got the same errors that led me to commenting these but it's because of opencensus-shim: the OC Tracer wires its own scope info and that eventually propagates to this block. Is there a simple way to override the OC shim's scope? I don't see a clean way to do it but that may be my unfamiliarity with OC.


@Test
void testCrossOtelOcBoundary() {
Tracer tracer = testing().getOpenTelemetry().getTracer("opencensus-shim", "0.0.0");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

conventional name we use for test tracers, also then the assertion TelemetryDataUtil` about the version won't fail

Suggested change
Tracer tracer = testing().getOpenTelemetry().getTracer("opencensus-shim", "0.0.0");
Tracer tracer = testing().getOpenTelemetry().getTracer("test");

public class OpencensusShimInstrumentationModule extends InstrumentationModule {

public OpencensusShimInstrumentationModule() {
super("opencensus-shim", "io.opentelemetry.opencensusshim");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
super("opencensus-shim", "io.opentelemetry.opencensusshim");
super("opencensus-shim");

Comment on lines +54 to +55
.hasAttributes(
Attributes.of(AttributeKey.booleanKey("internal-only"), true))));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
.hasAttributes(
Attributes.of(AttributeKey.booleanKey("internal-only"), true))));
.hasAttributesSatisfyingExactly(
equalTo(AttributeKey.booleanKey("internal-only"), true))));


@Override
public List<TypeInstrumentation> typeInstrumentations() {
return Arrays.asList(new OpenTelemetryCtxInstrumentation());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Collections.singletonList, which we usually static import (see https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/contributing/style-guideline.md#static-imports)

Suggested change
return Arrays.asList(new OpenTelemetryCtxInstrumentation());
return singletonList(new OpenTelemetryCtxInstrumentation());

* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.opencensusshim;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
package io.opentelemetry.opencensusshim;
package io.opentelemetry.javaagent.instrumentation.opencensusshim;

Comment on lines +26 to +30
@Override
public boolean isHelperClass(String className) {
return className.equals("io.opentelemetry.opencensusshim.ContextExtractor");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isHelperClass shouldn't be needed after updating the package name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OH I think I'm piecing that together now -- I don't think I ever knew that was required to make that work.

I tried to move this as you suggested, but unfortunately, this one's a bit of a pickle: the ContextExtractor class relies on being in that package to access the package-private io.opentelemetry.opencensusshim.OpenTelemetrySpanImpl class. I can probably split up the bits into static pieces though? Any other suggestions on how to address that?

@dmarkwat
Copy link
Copy Markdown
Contributor Author

dmarkwat commented Oct 24, 2022

Thank you! It was quite an adventure and indeed tricky, but I'm happy I was able to distill the misalignment down to such a simple test.

Thanks for the suggestions -- learning new things every time I touch this repo 😄 ! I left some comments and questions of my own bc unfortunately some of these make for an awkward alignment with the well-trodden setup already in the repo.

I've spent some time thinking about what I wrote up in the issue, and I don't know if you had a chance to read it yet yourself, but I'm coming around to the thought that perhaps the cleanest path to solving this may just be to update the opencensus-shim to completely delegate all the calls to the original instances of objects returned by the underlying otel framework.

impose/implement the change in the upstream (in this case, opencensus-shim) to delegate all the methods to the wrapped object

My thinking is two-fold: 1) the OC shim's wrappers for span, context, etc. don't fully delegate all the calls to the otel-sourced object instances at present (example: not all methods are delegated, in particular and especially, storeInContext), but if they did this PR here wouldn't be necessary and it would make the shim even "thinner" and maybe easier to work with in these situations; and 2) while instrumentation wouldn't be required here any longer, I think keeping the two tests in this PR (one for the library w/o the javaagent and the other with the javaagent) could carry strong benefits forward as it would catch any regression in future iterations (where they live 🤷 not sure, but I personally think they could stand as value-add).

WDYT about that? I'm happy to write up a PR for that as well against opentelemetry-java, but equally happy to stick with this for now and see where the discussion goes.

@dmarkwat
Copy link
Copy Markdown
Contributor Author

Bump. Any thoughts? I made the separate PR which got some traction but it appears to be at a standstill?

@dmarkwat
Copy link
Copy Markdown
Contributor Author

Closing in favor of open-telemetry/opentelemetry-java#4900 and its test-only counterpart, #7488.

@dmarkwat dmarkwat closed this Jan 16, 2023
@dmarkwat dmarkwat deleted the opencensus-shim branch January 16, 2023 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants