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

Add include_trace_context property to logger builder #5366

Closed
wants to merge 2 commits into from

Conversation

jack-berg
Copy link
Member

The spec for LoggerProvider's "Get a Logger" operation includes a include_trace_context parameter, which defaults to true. If include_trace_context=true, then the SpanContext field of emitted LogRecords should be extracted from the current context. If false, then the SpanContext field of emitted LogRecords should be extracted from the explicitly set context, or otherwise invalid.

I've haven't included this so far because the use case is rather esoteric and we haven't seen users ask for it. Its used in situations where the emitted log records are coming from threads which may have active spans, but which are not related to the emitted log records. Its probably more useful in event scenarios. But you can also imagine valid logging scenarios, where a log framework has its own holder for span context and deriving SpanContext from current span context is invalid.

Anyway, that's the backstory.

I've opened this PR because the spec says the "API MUST accept the following parameter". However, we could add it in a backwards compatible way after an initial stable release. Additionally, there are other cases where our implementation doesn't include all the "MUST" elements of the specification. Our ReadWriteLogRecord has placeholders for reading / writing fields.

@jack-berg jack-berg requested a review from a team April 10, 2023 19:21
@codecov
Copy link

codecov bot commented Apr 10, 2023

Codecov Report

Patch coverage: 95.83% and project coverage change: -0.01 ⚠️

Comparison is base (0a34867) 91.20% compared to head (c03cadf) 91.20%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5366      +/-   ##
============================================
- Coverage     91.20%   91.20%   -0.01%     
- Complexity     4866     4869       +3     
============================================
  Files           546      546              
  Lines         14373    14388      +15     
  Branches       1351     1352       +1     
============================================
+ Hits          13109    13122      +13     
- Misses          875      876       +1     
- Partials        389      390       +1     
Impacted Files Coverage Δ
.../opentelemetry/api/logs/DefaultLoggerProvider.java 87.50% <0.00%> (-12.50%) ⬇️
...io/opentelemetry/sdk/logs/SdkLogRecordBuilder.java 97.91% <100.00%> (+0.29%) ⬆️
...main/java/io/opentelemetry/sdk/logs/SdkLogger.java 100.00% <100.00%> (ø)
...va/io/opentelemetry/sdk/logs/SdkLoggerBuilder.java 100.00% <100.00%> (ø)
...a/io/opentelemetry/sdk/logs/SdkLoggerProvider.java 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

*
* @return this
*/
LoggerBuilder excludeTraceContext();
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

the name of this seems weird to me... since it's only about the span context, not the trace as a whole. 🤔 Is this something that should be adjusted in the spec?

Copy link
Member Author

Choose a reason for hiding this comment

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

This one is a bit weird. SpanContext shows up in the trace API specification, and in our API, yet the spec log data model refers to these fields as "Trace Context Fields". I can argue both side of this:

In favor of trace context:

  • Its the context that links logs to the "tracing signal"
  • It contains more than just a span's context (i.e trace id and trace flags)
  • W3C refers to this set of things as

In favor of span context:

  • We have a SpanContext interface
  • The spec refers to this bag of data (spanid, traceid, trace flags, trace state) as SpanContext

Given that the log data model is stable, can we change the log data model to refer to "Span Context Fields" instead of trace context fields? If so, we could / should change this to include_span_context instead of include_trace_context.

@tigrannajaryan curious to get your thoughts on this.

Copy link
Member

Choose a reason for hiding this comment

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

I think we have been using Trace Context and Span Context interchangeably a lot. Span Context is probably a slightly more accurate term since it matters which span in a trace we are referring to from a log. I don't mind renaming this in the spec and in the data model and I don't think it is a breaking change, to me it is just a terminology clarification, we should be able to do it and there are no functional changes.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, one thing that may prevent us from doing it is that we consider it to be valid for a Log Record to reference a trace_id but have no associated span_id. You won't encounter it in Otel-generated data but some weird external data sources like this may be possible so we allowed for it in the data model.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we have been using Trace Context and Span Context interchangeably a lot.

That's been my experience as well. Here are usage of trace context, tracecontext, span context and spancontext in the specification.

I don't feel strongly either way about this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

If span context and trace context are used interchangeably, its probably not a big deal for otel java to name this excludeSpanContext instead, given that we have a SpanContext interface which would be good to reference in the javadoc.

Copy link
Contributor

Choose a reason for hiding this comment

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

how about just "excludeContext" in case we might want to also start pulling in baggage or something later?

Comment on lines +38 to +39
* Specify that emitted log records SHOULD NOT automatically include trace context from the {@link
* Context#current()}.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should say "span context" rather than "trace context" (since I don't think that's a thing outside of the W3C propagator). Also, should we include a link to the SpanContext class in the javadoc for completeness?

@jack-berg
Copy link
Member Author

FYI, we're considering removing include_trace_context here, so let's pause any discussion on this PR until that resolves.

@jack-berg
Copy link
Member Author

No longer need as the spec dropped this parameter in #3397.

@jack-berg jack-berg closed this Apr 14, 2023
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.

4 participants