-
Notifications
You must be signed in to change notification settings - Fork 845
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
Enable strict context check and fix some context issues. #2637
Changes from 1 commit
813fd73
8a6fc39
55aa488
b97c671
be61373
b2232ce
ecaa951
e49eef7
9d5adcd
be8bfe4
33a9fe6
2d32b4e
dd99146
b4b89ef
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 |
---|---|---|
|
@@ -128,10 +128,6 @@ private void populateGenericAttributes(Span span, ExecutionAttributes attributes | |
@Override | ||
public void afterExecution( | ||
Context.AfterExecution context, ExecutionAttributes executionAttributes) { | ||
Scope scope = executionAttributes.getAttribute(SCOPE_ATTRIBUTE); | ||
if (scope != null) { | ||
scope.close(); | ||
} | ||
io.opentelemetry.context.Context otelContext = getContext(executionAttributes); | ||
clearAttributes(executionAttributes); | ||
Span span = Span.fromContext(otelContext); | ||
|
@@ -168,6 +164,10 @@ public void onExecutionFailure( | |
} | ||
|
||
private void clearAttributes(ExecutionAttributes executionAttributes) { | ||
Scope scope = executionAttributes.getAttribute(SCOPE_ATTRIBUTE); | ||
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. 😱 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. 💯 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. I don't get it. Both why this change is significant and your reaction to it :D 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. It's a real context leak with big damage - if sync AWS SDK request failed and a subsequent client request of some form was made, it would parent to the AWS SDK request (well it'd be suppressed as a result usually)! Hooray for strict context checking |
||
if (scope != null) { | ||
scope.close(); | ||
} | ||
executionAttributes.putAttribute(CONTEXT_ATTRIBUTE, null); | ||
executionAttributes.putAttribute(AWS_SDK_REQUEST_ATTRIBUTE, null); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,3 @@ dependencies { | |
|
||
latestDepTestLibrary group: 'com.squareup.okhttp', name: 'okhttp', version: '[2.6,3)' | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,20 +27,18 @@ public void consumeMessageBefore(ConsumeMessageContext context) { | |
if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) { | ||
return; | ||
} | ||
Context traceContext = tracer.startSpan(Context.current(), context.getMsgList()); | ||
ContextAndScope contextAndScope = new ContextAndScope(traceContext, traceContext.makeCurrent()); | ||
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. Can 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. Yup, thanks |
||
context.setMqTraceContext(contextAndScope); | ||
Context otelContext = tracer.startSpan(Context.current(), context.getMsgList()); | ||
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. Like similar netty libraries, there's no thread guarantee for before and end. Since there's no downstream instrumentation it's not a big deal anyways 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. What about e.g. user-provided message hooks that want to augment existing span? 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. We will need to provide something like I hope such hooks will be able to use our instrumentation-api instead of that though. |
||
context.setMqTraceContext(otelContext); | ||
} | ||
|
||
@Override | ||
public void consumeMessageAfter(ConsumeMessageContext context) { | ||
if (context == null || context.getMsgList() == null || context.getMsgList().isEmpty()) { | ||
return; | ||
} | ||
if (context.getMqTraceContext() instanceof ContextAndScope) { | ||
ContextAndScope contextAndScope = (ContextAndScope) context.getMqTraceContext(); | ||
contextAndScope.closeScope(); | ||
tracer.end(contextAndScope.getContext()); | ||
if (context.getMqTraceContext() instanceof Context) { | ||
Context otelContext = (Context) context.getMqTraceContext(); | ||
tracer.end(otelContext); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import groovy.transform.stc.ClosureParams | |
import groovy.transform.stc.SimpleType | ||
import io.opentelemetry.api.OpenTelemetry | ||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.context.ContextStorage | ||
import io.opentelemetry.instrumentation.test.asserts.InMemoryExporterAssert | ||
import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner | ||
import io.opentelemetry.instrumentation.testing.util.TelemetryDataUtil | ||
|
@@ -36,6 +37,13 @@ abstract class InstrumentationSpecification extends Specification { | |
testRunner().clearAllExportedData() | ||
} | ||
|
||
def cleanup() { | ||
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. Hmm, perhaps we should consider adding an 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. Thanks for pointing out InstrumentationExtension - adding afterTest seemed a bit weird since it's the same code for agent and library. For now I just copied the code since it isn't so much and I think we can revisit later. |
||
ContextStorage storage = ContextStorage.get() | ||
if (storage instanceof AutoCloseable) { | ||
((AutoCloseable) storage).close() | ||
} | ||
} | ||
|
||
def cleanupSpec() { | ||
testRunner().afterTestClass() | ||
} | ||
|
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.
nice to see where this fails