|
24 | 24 | import io.opentelemetry.sdk.logs.export.LogRecordExporter; |
25 | 25 | import io.opentelemetry.sdk.trace.samplers.SamplingDecision; |
26 | 26 | import io.opentelemetry.sdk.trace.samplers.SamplingResult; |
27 | | -import io.opentelemetry.semconv.SemanticAttributes; |
| 27 | +import io.opentelemetry.semconv.ExceptionAttributes; |
28 | 28 | import java.util.Collection; |
29 | 29 | import java.util.List; |
30 | 30 | import java.util.function.Consumer; |
@@ -99,55 +99,58 @@ private CompletableResultCode internalExport(Collection<LogRecordData> logs) { |
99 | 99 | return CompletableResultCode.ofFailure(); |
100 | 100 | } |
101 | 101 | for (LogRecordData log : logs) { |
102 | | - try { |
103 | | - int severityNumber = log.getSeverity().getSeverityNumber(); |
104 | | - if (severityNumber < severityThreshold) { |
105 | | - continue; |
106 | | - } |
| 102 | + internalExport(log); |
| 103 | + } |
| 104 | + // always returning success, because all error handling is performed internally |
| 105 | + return CompletableResultCode.ofSuccess(); |
| 106 | + } |
107 | 107 |
|
108 | | - String stack = log.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE); |
| 108 | + private void internalExport(LogRecordData log) { |
| 109 | + try { |
| 110 | + int severityNumber = log.getSeverity().getSeverityNumber(); |
| 111 | + if (severityNumber < severityThreshold) { |
| 112 | + return; |
| 113 | + } |
109 | 114 |
|
110 | | - SamplingOverrides samplingOverrides = |
111 | | - stack != null ? exceptionSamplingOverrides : logSamplingOverrides; |
| 115 | + String stack = log.getAttributes().get(ExceptionAttributes.EXCEPTION_STACKTRACE); |
112 | 116 |
|
113 | | - SpanContext spanContext = log.getSpanContext(); |
114 | | - Double parentSpanSampleRate = log.getAttributes().get(AiSemanticAttributes.SAMPLE_RATE); |
| 117 | + SamplingOverrides samplingOverrides = |
| 118 | + stack != null ? exceptionSamplingOverrides : logSamplingOverrides; |
115 | 119 |
|
116 | | - AiSamplerForOverride sampler = samplingOverrides.getOverride(log.getAttributes()); |
| 120 | + SpanContext spanContext = log.getSpanContext(); |
| 121 | + Double parentSpanSampleRate = log.getAttributes().get(AiSemanticAttributes.SAMPLE_RATE); |
117 | 122 |
|
118 | | - if (sampler == null && spanContext.isValid() && !spanContext.getTraceFlags().isSampled()) { |
119 | | - // if there is no sampling override, and the log is part of an unsampled trace, then don't |
120 | | - // capture it |
121 | | - continue; |
122 | | - } |
| 123 | + AiSamplerForOverride sampler = samplingOverrides.getOverride(log.getAttributes()); |
123 | 124 |
|
124 | | - Double sampleRate = null; |
125 | | - if (sampler != null) { |
126 | | - SamplingResult samplingResult = |
127 | | - sampler.shouldSampleLog(spanContext, parentSpanSampleRate); |
128 | | - if (samplingResult.getDecision() != SamplingDecision.RECORD_AND_SAMPLE) { |
129 | | - continue; |
130 | | - } |
131 | | - sampleRate = samplingResult.getAttributes().get(AiSemanticAttributes.SAMPLE_RATE); |
132 | | - } |
| 125 | + if (sampler == null && spanContext.isValid() && !spanContext.getTraceFlags().isSampled()) { |
| 126 | + // if there is no sampling override, and the log is part of an unsampled trace, |
| 127 | + // then don't capture it |
| 128 | + return; |
| 129 | + } |
133 | 130 |
|
134 | | - if (sampleRate == null) { |
135 | | - sampleRate = parentSpanSampleRate; |
| 131 | + Double sampleRate = null; |
| 132 | + if (sampler != null) { |
| 133 | + SamplingResult samplingResult = sampler.shouldSampleLog(spanContext, parentSpanSampleRate); |
| 134 | + if (samplingResult.getDecision() != SamplingDecision.RECORD_AND_SAMPLE) { |
| 135 | + return; |
136 | 136 | } |
| 137 | + sampleRate = samplingResult.getAttributes().get(AiSemanticAttributes.SAMPLE_RATE); |
| 138 | + } |
| 139 | + |
| 140 | + if (sampleRate == null) { |
| 141 | + sampleRate = parentSpanSampleRate; |
| 142 | + } |
137 | 143 |
|
138 | | - logger.debug("exporting log: {}", log); |
| 144 | + logger.debug("exporting log: {}", log); |
139 | 145 |
|
140 | | - // TODO (trask) no longer need to check AiSemanticAttributes.SAMPLE_RATE in map() method |
141 | | - TelemetryItem telemetryItem = mapper.map(log, stack, sampleRate); |
142 | | - telemetryItemConsumer.accept(telemetryItem); |
| 146 | + // TODO (trask) no longer need to check AiSemanticAttributes.SAMPLE_RATE in map() method |
| 147 | + TelemetryItem telemetryItem = mapper.map(log, stack, sampleRate); |
| 148 | + telemetryItemConsumer.accept(telemetryItem); |
143 | 149 |
|
144 | | - exportingLogLogger.recordSuccess(); |
145 | | - } catch (Throwable t) { |
146 | | - exportingLogLogger.recordFailure(t.getMessage(), t, EXPORTER_MAPPING_ERROR); |
147 | | - } |
| 150 | + exportingLogLogger.recordSuccess(); |
| 151 | + } catch (Throwable t) { |
| 152 | + exportingLogLogger.recordFailure(t.getMessage(), t, EXPORTER_MAPPING_ERROR); |
148 | 153 | } |
149 | | - // always returning success, because all error handling is performed internally |
150 | | - return CompletableResultCode.ofSuccess(); |
151 | 154 | } |
152 | 155 |
|
153 | 156 | @Override |
|
0 commit comments