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

Change Log flags field to TraceFlags #3811

Closed
wants to merge 1 commit into from

Conversation

jack-berg
Copy link
Member

Part of Issue #3804.

Adjust the log int getFlags() field to TraceFlags getTraceFlags().

@@ -47,7 +48,7 @@
LogData.builder(RESOURCE, InstrumentationLibraryInfo.create("instrumentation2", "2"))
.setName("testLog2")
.setBody("body2")
.setFlags(0)
.setTraceFlags(TraceFlags.getDefault())
Copy link
Contributor

Choose a reason for hiding this comment

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

might be nice to have one example that's sampled, as well. That goes for all the tests in this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are a lot of tests that create LogData but most of the functionality under test doesn't concern the trace flags field directly. I'd prefer to limit testing of the different shapes of trace flags to the tests that are directly concerned with serializing / deserializing trace flag values. That would include OtlpJsonLoggingLogExporter, LogsRequestMarshalerTest, which tests serialization of LogData to proto, and OtlpExporterIntegrationTest, which tests exporting to the collector and back to a java process.

If we have tests that validate the correctness of the low level code, then we can trust that it will work for higher level code that consumes it.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good to me. TraceFlags aren't a mandatory field, correct? We could just leave them out of the high level tests altogether in most cases, I'd assume.

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of three methods, should it be setSpanContext?

Copy link
Contributor

Choose a reason for hiding this comment

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

Another conceptual question, I don't think we have trace flags on metrics exemplar. It feels like the spancontext information added to a log would match what's added to an exemplar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I don't think its worth merging the PR if its just going to change in the near future.

Some additional food for though:

  • The Log4j2 OpenTelemetryContextDataProvider currently associates span context with Log4j2 log events.
  • In my Log4j2 appender prototype, I read those fields out of the context map and associate them with the LogBuilder (note I haven't extracted the TRACE_FLAGS field yet).
  • If we depend on the log appenders calling Context.current() to get context, rather than first injecting the context into the log as is done in Log4j2, then we are assuming that the appenders are called synchronously from the same thread when a logger.log(...) is invoked, right? Because if the appender is not called synchronously on the same thread, then Context.current() won't result the right context. I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting - the context provider can't inject Context itself because it needs to set a string map. So if we rely on the injection than baggage would also all need to be injected as key value pairs. Any plans for that out of curiosity?

I have a feeling that expecting the OTel appender to be synchronous is going to be more practical but not sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

So if we rely on the injection than baggage would also all need to be injected as key value pairs. Any plans for that out of curiosity?

I haven't heard anything about logs and baggage. @tigrannajaryan do you have any insight into this?

I have a feeling that expecting the OTel appender to be synchronous is going to be more practical but not sure.

Log4j2 has the AsyncAppender, which allows you to wrap other appenders and causes log events to be written to them on a separate thread. We'd have to tell users they can't wrap the otel appender in an AsyncAppender. It would be a bit strange, but not outright wrong, for a user to use the otel appender with the AsyncAppender, since BatchLogProcessor already exports on a separate thread.

Logback has the same concept.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I've been worrying about async appenders since the very early days of the logging project. I don't know that we have any good solution for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

We discussed in the 11/4 Java + Instrumentation Office hours and decided to have a LogBuilder#setContext(Context) method and LogData#getSpanContext().

@codecov
Copy link

codecov bot commented Nov 1, 2021

Codecov Report

Merging #3811 (97cf50a) into main (1f22239) will increase coverage by 0.17%.
The diff coverage is 87.50%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #3811      +/-   ##
============================================
+ Coverage     89.22%   89.39%   +0.17%     
- Complexity     4010     4017       +7     
============================================
  Files           481      481              
  Lines         12430    12432       +2     
  Branches       1207     1207              
============================================
+ Hits          11091    11114      +23     
+ Misses          926      910      -16     
+ Partials        413      408       -5     
Impacted Files Coverage Δ
.../java/io/opentelemetry/sdk/logs/SdkLogEmitter.java 66.66% <0.00%> (ø)
...n/java/io/opentelemetry/sdk/logs/data/LogData.java 100.00% <ø> (ø)
...va/io/opentelemetry/sdk/logs/data/LogDataImpl.java 100.00% <ø> (ø)
...etry/exporter/otlp/internal/logs/LogMarshaler.java 67.10% <100.00%> (+0.43%) ⬆️
...io/opentelemetry/sdk/logs/data/LogDataBuilder.java 100.00% <100.00%> (ø)
...emetry/api/baggage/propagation/PercentEscaper.java 79.69% <0.00%> (-4.52%) ⬇️
...metry/sdk/metrics/export/PeriodicMetricReader.java 81.66% <0.00%> (-3.34%) ⬇️
...elemetry/exporter/otlp/internal/MarshalerUtil.java 95.50% <0.00%> (+2.24%) ⬆️
...lemetry/exporter/otlp/internal/JsonSerializer.java 93.54% <0.00%> (+3.22%) ⬆️
...emetry/exporter/otlp/internal/ProtoSerializer.java 100.00% <0.00%> (+4.10%) ⬆️
... and 7 more

Continue to review full report at Codecov.

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

Copy link
Contributor

@breedx-splk breedx-splk left a comment

Choose a reason for hiding this comment

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

Looks ok to me.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

LGTM :)

@jack-berg jack-berg mentioned this pull request Nov 8, 2021
@jack-berg
Copy link
Member Author

Replacing this PR with #3837, which includes the changes we discussed in the 11/4 Java + Instrumentation Office Hours.

@jack-berg jack-berg closed this Nov 8, 2021
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.

5 participants