-
Notifications
You must be signed in to change notification settings - Fork 870
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 service.name
to MDC
#9647
Add service.name
to MDC
#9647
Conversation
cf86974
to
4e0102e
Compare
Test fails because it uses a type that is not available due to which instrumentation is not applied
Place that class in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap |
8d344b5
to
1c02310
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few comments below.
...p/src/main/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolder.java
Outdated
Show resolved
Hide resolved
...p/src/main/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolder.java
Outdated
Show resolved
Hide resolved
...c/test/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolderTest.java
Outdated
Show resolved
Hide resolved
...c/test/java/io/opentelemetry/javaagent/bootstrap/ConfiguredResourceAttributesHolderTest.java
Outdated
Show resolved
Hide resolved
33e527a
to
07c9fca
Compare
@@ -5,6 +5,7 @@ plugins { | |||
base.archivesName.set("${base.archivesName.get()}-autoconfigure") | |||
|
|||
dependencies { | |||
implementation(project(":javaagent-bootstrap")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Is this safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it is not. library modules can not depend on :javaagent-bootstrap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the appropriate way to provide the resource attribute for the mdc here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be acceptable to have a compile only dependency and in the code first verify that the class is present with Class.forName before using it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?
try {
Class.forName("io.opentelemetry.javaagent.bootstrap.ConfiguredResourceAttributesHolder");
contextData.putAll(ConfiguredResourceAttributesHolder.getResourceAttributes());
} catch (ClassNotFoundException ignore) {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typically you'd do the class presence check only once in class initializer and set a boolean based on that and use that boolean everywhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laurit how does it look?
1f02dc6
to
9527b78
Compare
cd4020c
to
6ec28c2
Compare
@@ -25,6 +26,19 @@ | |||
* #supplyContextData()} is called when a log entry is created. | |||
*/ | |||
public class OpenTelemetryContextDataProvider implements ContextDataProvider { | |||
|
|||
private boolean configuredResourceAttributeAccessible; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to a static final field and change what you have in constructor into a static method that returns a boolean and use it to initialize the field
6ec28c2
to
8653b1c
Compare
|
||
private static String[] getConfiguredAttributes() { | ||
String resourceAttributes = | ||
ConfigPropertiesUtil.getString("otel.instrumentation.mdc.resource-attributes"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use InstrumentationConfig.get().getList("otel.instrumentation.mdc.resource-attributes", emptyList())
but InstrumentationConfig
isn't probably accessible from here. InstrumentationConfig
gets the properties from the sdk and could support more source than what ConfigPropertiesUtil
uses. ConfigPropertiesUtil
is usually used for library instrumentations and InstrumentationConfig
in javaagent. Could you try moving this class to https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/bootstrap/internal so you could use InstrumentationConfig
. Sorry for not noticing this before, should be the last thing from me.
80bea6d
to
857db6e
Compare
@cleverchuk I create a PR for your PR cleverchuk#1 that adds tests and makes it so that the resource attributes are added to mdc even if there is no active span. |
@cleverchuk could you merge cleverchuk#1 |
…ation.mdc.resource-attributes` that will be used to configure `Resource` attributes to be added to logging map diagnostic context.
- use assertJ for unit test assertions - use plural for method and field names - add compile only dependency on `:javaagent-bootstrap` for `instrumentation:log4j:log4j-context-data:log4j-context-data-2.17:library-autoconfigure`
- use implementation dependency on `:javaagent-bootstrap`
- use compile dependency on `:javaagent-bootstrap` and do runtime check before use.
- refactor constructor to static method
- move ConfiguredResourceAttributesHolder to javaagent-extension-api
5fe7b75
to
4e80330
Compare
@trask I added the docs, could you review |
thx @laurit wdyt of renaming
to
similar to discussion at #9758 (comment)? |
…tation.common.mdc.resource-attributes
@trask renamed |
(#9297) add new instrumentation config
otel.instrumentation.mdc.resource-attributes
that will be used to configureResource
attributes to be added to logging map diagnostic context.