-
Notifications
You must be signed in to change notification settings - Fork 986
spring starter: add thread details instrumentation / configure logging span exporter #14117
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
base: main
Are you sure you want to change the base?
Changes from all commits
e12c040
c784652
e1d9749
365a4fa
71be296
e052a83
c500373
d06cd03
522cac1
addc0ef
9d652a1
a7d8638
14e2b0f
ccdc104
dde299d
ca19d4b
44f6509
5e22b90
d2b310d
97ff34e
e057a53
db546ce
88d3cec
ed45c30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.logging; | ||
|
||
import io.opentelemetry.exporter.logging.LoggingSpanExporter; | ||
import io.opentelemetry.instrumentation.internal.logging.LoggingSpanExporterConfigurer; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.SdkEnabled; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
@Conditional(SdkEnabled.class) | ||
// for backward compatibility with declarative configuration | ||
@ConditionalOnProperty(name = "otel.debug", havingValue = "true") | ||
@ConditionalOnClass(LoggingSpanExporter.class) | ||
@Configuration | ||
public class LoggingExporterAutoConfiguration { | ||
|
||
@Bean | ||
public AutoConfigurationCustomizerProvider loggingOtelCustomizer() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why only traces and not also metrics and logs? (maybe split the debug behavior out into separate PR? I reviewed the thread stuff and it all looks good to me) |
||
return p -> | ||
p.addTracerProviderCustomizer( | ||
(builder, config) -> { | ||
LoggingSpanExporterConfigurer.enableLoggingExporter(builder, config); | ||
return builder; | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.internal.instrumentation.thread; | ||
|
||
import io.opentelemetry.instrumentation.internal.thread.AddThreadDetailsSpanProcessor; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.internal.ConditionalOnEnabledInstrumentation; | ||
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
@ConditionalOnEnabledInstrumentation(module = "common.thread-details", enabledByDefault = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agent enables this by default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #14144 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trask please check if thread details should be disabled by default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I forgot to raise it in semconv meeting, I've added it to next week's agenda so I won't forget There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trask do you have an update? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it should ideally be opt-in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then it looks like we can leave it as is |
||
@Configuration | ||
@SuppressWarnings("OtelPrivateConstructorForUtilityClass") | ||
public class ThreadDetailsAutoConfiguration { | ||
|
||
@Bean | ||
public AutoConfigurationCustomizerProvider threadDetailOtelCustomizer() { | ||
return p -> | ||
p.addTracerProviderCustomizer( | ||
(builder, config) -> { | ||
builder.addSpanProcessor(new AddThreadDetailsSpanProcessor()); | ||
return builder; | ||
}); | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.internal.logging; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import io.opentelemetry.exporter.logging.LoggingSpanExporter; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; | ||
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public class LoggingSpanExporterConfigurer { | ||
|
||
private LoggingSpanExporterConfigurer() {} | ||
|
||
public static void enableLoggingExporter( | ||
SdkTracerProviderBuilder builder, ConfigProperties config) { | ||
// don't install another instance if the user has already explicitly requested it. | ||
if (loggingExporterIsNotAlreadyConfigured(config)) { | ||
builder.addSpanProcessor(SimpleSpanProcessor.create(LoggingSpanExporter.create())); | ||
} | ||
} | ||
|
||
private static boolean loggingExporterIsNotAlreadyConfigured(ConfigProperties config) { | ||
return !config.getList("otel.traces.exporter", emptyList()).contains("logging"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
io.opentelemetry.instrumentation.resources.ResourceProviderPropertiesCustomizer | ||
io.opentelemetry.instrumentation.internal.resources.ResourceProviderPropertiesCustomizer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.internal.thread; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.sdk.trace.ReadWriteSpan; | ||
import io.opentelemetry.sdk.trace.SpanProcessor; | ||
import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class AddThreadDetailsSpanProcessorTest { | ||
|
||
private final ReadWriteSpan span = mock(ReadWriteSpan.class); | ||
|
||
private final SpanProcessor spanProcessor = new AddThreadDetailsSpanProcessor(); | ||
|
||
@Test | ||
void onStart() { | ||
assertThat(spanProcessor.isStartRequired()).isTrue(); | ||
} | ||
|
||
@Test | ||
void setThreadAttributes() { | ||
Thread thread = Thread.currentThread(); | ||
spanProcessor.onStart(Context.root(), span); | ||
|
||
verify(span).setAttribute(ThreadIncubatingAttributes.THREAD_ID, thread.getId()); | ||
verify(span).setAttribute(ThreadIncubatingAttributes.THREAD_NAME, thread.getName()); | ||
verifyNoMoreInteractions(span); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
io.opentelemetry.instrumentation.resources.ResourceProviderPropertiesCustomizerTest$Provider | ||
io.opentelemetry.instrumentation.internal.resources.ResourceProviderPropertiesCustomizerTest$Provider |
Uh oh!
There was an error while loading. Please reload this page.