Skip to content

Commit

Permalink
Sample logs consistently with traces
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanbisutti committed Oct 22, 2024
1 parent 62df132 commit ca34e38
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import io.opentelemetry.api.logs.LogRecordBuilder;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.internal.AttributesMap;
Expand Down Expand Up @@ -119,20 +121,24 @@ public void emit() {
this.observedTimestampEpochNanos == 0
? this.loggerSharedState.getClock().now()
: this.observedTimestampEpochNanos;
loggerSharedState
.getLogRecordProcessor()
.onEmit(
context,
SdkReadWriteLogRecord.create(
loggerSharedState.getLogLimits(),
loggerSharedState.getResource(),
instrumentationScopeInfo,
timestampEpochNanos,
observedTimestampEpochNanos,
Span.fromContext(context).getSpanContext(),
severity,
severityText,
body,
attributes));
SpanContext spanContext = Span.fromContext(context).getSpanContext();
TraceFlags traceFlags = spanContext.getTraceFlags();
if (!traceFlags.isSampled()) {
loggerSharedState
.getLogRecordProcessor()
.onEmit(
context,
SdkReadWriteLogRecord.create(
loggerSharedState.getLogLimits(),
loggerSharedState.getResource(),
instrumentationScopeInfo,
timestampEpochNanos,
observedTimestampEpochNanos,
spanContext,
severity,
severityText,
body,
attributes));
}
}
}

0 comments on commit ca34e38

Please sign in to comment.