Skip to content
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

Capture span stack trace #21

Merged
merged 12 commits into from
Nov 14, 2023
Merged

Capture span stack trace #21

merged 12 commits into from
Nov 14, 2023

Conversation

SylvainJuge
Copy link
Member

@SylvainJuge SylvainJuge commented Oct 16, 2023

Capture span stack trace with a simple exception

Refers to #16

@SylvainJuge SylvainJuge self-assigned this Nov 7, 2023
@AlexanderWert
Copy link
Member

Make code.stacktrace not being overwritten when it's already present.

Comment on lines +63 to +72
assertThat(testExporter.getFinishedSpanItems())
.hasSize(1)
.first()
.satisfies(
spanData ->
assertThat(spanData)
.hasAttributesSatisfying(
satisfies(
ElasticAttributes.SPAN_STACKTRACE,
AbstractCharSequenceAssert::isNotEmpty)));
Copy link
Member Author

Choose a reason for hiding this comment

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

[for reviewer] otel test utilities provide the assertj extension for easily testing for custom attributes.

Comment on lines +48 to +49
.addSpanProcessor(elasticSpanProcessor)
.addSpanProcessor(SimpleSpanProcessor.create(elasticSpanExporter))
Copy link
Member Author

Choose a reason for hiding this comment

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

[for reviewer] this emulates how our exporter is usually set up in the agent: first our exporter that modifies spans, then another that exports it. Here we are using the simple exporter that does not use batching and is synchronous.


// do not overwrite stacktrace if present
if (span.getAttribute(ElasticAttributes.SPAN_STACKTRACE) == null) {
// TODO should we filter-out the calling code that is within the agent: at least onEnd +
Copy link
Member Author

Choose a reason for hiding this comment

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

[for reviewer] I don't know if any filtering on the stack trace is applied here, thus I'll leave it as-it for now and wait to have the kibana implementation to see if any filtering is applied on the UI side.


// unfortunately here we get a read-only span that has already been ended, thus even a cast to
// ReadWriteSpan
// does not allow us from adding extra span attributes
if (spanExporter != null) {
spanContextData.setSelfTime(selfTime);
spanExporter.report(spanContext, spanContextData);
spanExporter.addAttribute(
spanContext, ElasticAttributes.SELF_TIME, spanContextData.getSelfTime());
Copy link
Member Author

Choose a reason for hiding this comment

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

[for reviewer] this is the only change in this file, the rest is mostly renaming things.

testImplementation("io.opentelemetry:opentelemetry-sdk")
testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common")
testImplementation("io.opentelemetry:opentelemetry-sdk-testing")
testImplementation("org.assertj:assertj-core:3.24.2") // TODO : remove version for assertj
Copy link
Member Author

Choose a reason for hiding this comment

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

[for reviewer] this will likely be handled with #8

@SylvainJuge SylvainJuge marked this pull request as ready for review November 13, 2023 15:43
@SylvainJuge SylvainJuge merged commit 72f4eea into elastic:main Nov 14, 2023
@SylvainJuge SylvainJuge deleted the span-stack branch November 14, 2023 12:56
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.

3 participants