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

[Tracer] Adds SpanEvents Support for DD and OTEL #2754

Merged
merged 36 commits into from
Aug 21, 2024

Conversation

link04
Copy link
Contributor

@link04 link04 commented Jul 9, 2024

Description

Adding support for SpanEvents, related RFC, currently, added a SpanEvent class and ExceptionSpanEvent which inherits from it to add specialized exception events to the Span.

Related PRs:

Reviewer checklist

  • Test coverage seems ok.
  • Appropriate labels assigned.

@codecov-commenter
Copy link

codecov-commenter commented Jul 9, 2024

Codecov Report

Attention: Patch coverage is 97.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.47%. Comparing base (14de5d5) to head (11478f5).
Report is 38 commits behind head on master.

Files with missing lines Patch % Lines
src/DDTrace/OpenTelemetry/Span.php 95.83% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2754      +/-   ##
============================================
- Coverage     80.74%   78.47%   -2.27%     
- Complexity     2452     2463      +11     
============================================
  Files           144      170      +26     
  Lines         14344    18190    +3846     
  Branches          0      913     +913     
============================================
+ Hits          11582    14275    +2693     
- Misses         2762     3420     +658     
- Partials          0      495     +495     
Flag Coverage Δ
appsec-extension 69.27% <ø> (?)
tracer-extension 78.27% <ø> (ø)
tracer-php 82.00% <97.33%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/DDTrace/OpenTelemetry/Context.php 86.29% <100.00%> (+0.45%) ⬆️
src/DDTrace/OpenTelemetry/SpanBuilder.php 93.84% <100.00%> (+1.32%) ⬆️
src/DDTrace/OpenTelemetry/Span.php 92.00% <95.83%> (+5.73%) ⬆️

... and 26 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14de5d5...11478f5. Read the comment docs.

@pr-commenter
Copy link

pr-commenter bot commented Jul 9, 2024

Benchmarks

Benchmark execution time: 2024-08-19 16:38:41

Comparing candidate commit aadf273 in PR branch maximo/span-events-support with baseline commit d75a84d in branch master.

Found 0 performance improvements and 4 performance regressions! Performance is the same for 174 metrics, 0 unstable metrics.

scenario:LaravelBench/benchLaravelOverhead-opcache

  • 🟥 execution_time [+100.383µs; +230.677µs] or [+3.530%; +8.111%]

scenario:PDOBench/benchPDOBaseline-opcache

  • 🟥 execution_time [+14.913µs; +17.779µs] or [+8.866%; +10.570%]

scenario:PDOBench/benchPDOOverhead-opcache

  • 🟥 execution_time [+6.113µs; +15.870µs] or [+2.229%; +5.786%]

scenario:TraceSerializationBench/benchSerializeTrace

  • 🟥 execution_time [+5.952µs; +7.748µs] or [+3.876%; +5.046%]

ext/ddtrace.stub.php Outdated Show resolved Hide resolved
ext/ddtrace.stub.php Outdated Show resolved Hide resolved
ext/ddtrace.c Outdated Show resolved Hide resolved
ext/ddtrace.c Outdated Show resolved Hide resolved
Comment on lines 117 to 120
// Update span metadata based on exception attributes
$this->setAttribute(Tag::ERROR_MSG, $exceptionAttributes['exception.message']);
$this->setAttribute(Tag::ERROR_TYPE, $exceptionAttributes['exception.type']);
$this->setAttribute(Tag::ERROR_STACK, $exceptionAttributes['exception.stacktrace']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure about this? Exceptions generally should only be added on spans if they escape their span.

Choose a reason for hiding this comment

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

This is by design, to match what our Datadog Agent does for OTEL Events when it receives OTLP traces. If there are any exception events on a span, then the last event that is added will be used to populate the error tagging fields on the span.

Note: We do not update the span.Error field when calling this method. To update the span.Error field, the user would have to call the OpenTelemetry span.SetStatus API with the Error status.

Copy link
Collaborator

Choose a reason for hiding this comment

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

error is set automatically when error.message or error.type are present. So, at least that assumption is not correct here.

When manually adding errors, users are supposed to only add error.message and error = 1 is automatically added for them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also IIRC that behaviour of populating error.message is a fallback behaviour from the ages where no span event support existed in the UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @bwoebi, I've been looking into this ask here since I thought for us to work around this I could check if the span was an error or not, if not then reset the error tag but I am not sure how to accomplish this, for example I saw that the error can be removed from the metrics object using unset($this->span->metrics[Tag::ERROR]); but couldn't find a way to do so for the body of the Span and wanted to check what you'd recommend.

Copy link
Collaborator

@bwoebi bwoebi Aug 5, 2024

Choose a reason for hiding this comment

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

What I would recommend is not doing this, honestly.
Like, it's a bad idea which goes against the defined semantics of the tracer. In the PHP tracer, error_msg/error_type is reserved for exceptions escaping the span.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you mean, will go ahead with only adding the stack tag for now and later connect with Error Tracking to try getting the details from the span event instead, does that sounds better at the moment?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes.

ext/ddtrace.c Outdated Show resolved Hide resolved
ext/ddtrace.c Outdated Show resolved Hide resolved
ext/ddtrace.c Show resolved Hide resolved
ext/ddtrace.stub.php Outdated Show resolved Hide resolved
@bwoebi bwoebi force-pushed the maximo/span-events-support branch from 257b6f1 to 853e555 Compare August 8, 2024 16:44
ext/ddtrace.c Outdated
}
}

if (attributes && Z_TYPE_P(attributes) == IS_ARRAY) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (attributes && Z_TYPE_P(attributes) == IS_ARRAY) {
if (Z_TYPE_P(attributes) == IS_ARRAY) {

Nit: redundant.

$event = new Event(
$datadogSpanEvent->name,
(int)$datadogSpanEvent->timestamp,
Attributes::create((array)$datadogSpanEvent->attributes ?? [])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This creates an OTel-Event, but it won't include the exception. Can you generate the right exception-attributes here on the fly? if $datadogSpanEvent instanceof ExceptionSpanEvent? (i.e. exception.stacktrace, exception.type, exception.message)?

Copy link
Collaborator

@bwoebi bwoebi Aug 9, 2024

Choose a reason for hiding this comment

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

I.e. same than what you do in SpanBuilder::recordException

@bwoebi
Copy link
Collaborator

bwoebi commented Aug 9, 2024

I see you updated libdatadog. Can you please also run make cbindgen in the repository root then, to keep the bindings up to date?

@link04 link04 requested review from a team as code owners August 10, 2024 00:16
Copy link
Collaborator

@bwoebi bwoebi left a comment

Choose a reason for hiding this comment

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

Thanks for implementing this Maximo :-)

@bwoebi bwoebi merged commit 4172cb8 into master Aug 21, 2024
648 of 686 checks passed
@bwoebi bwoebi deleted the maximo/span-events-support branch August 21, 2024 11:32
@github-actions github-actions bot added this to the 1.3.0 milestone Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants