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

Add service.name to MDC #9647

Merged

Conversation

cleverchuk
Copy link
Contributor

(#9297) add new instrumentation config otel.instrumentation.mdc.resource-attributes that will be used to configure Resource attributes to be added to logging map diagnostic context.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 10, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch 3 times, most recently from cf86974 to 4e0102e Compare October 10, 2023 20:42
@laurit
Copy link
Contributor

laurit commented Oct 11, 2023

Test fails because it uses a type that is not available due to which instrumentation is not applied

2023-10-10T21:01:07.5279882Z     [otel.javaagent 2023-10-10 21:01:05:834 +0000] [Test worker] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - Instrumentation skipped, mismatched references were found: logback-mdc [class io.opentelemetry.javaagent.instrumentation.logback.mdc.v1_0.LogbackMdcInstrumentationModule] on sun.misc.Launcher$AppClassLoader@73d16e93
2023-10-10T21:01:07.5282284Z     [otel.javaagent 2023-10-10 21:01:05:834 +0000] [Test worker] WARN io.opentelemetry.javaagent.tooling.instrumentation.MuzzleMatcher - -- io.opentelemetry.javaagent.instrumentation.logback.mdc.v1_0.LoggingEventInstrumentation$GetMdcAdvice:84 Missing class io.opentelemetry.javaagent.tooling.ConfiguredResourceAttributesHolder

Place that class in https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap

@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch 2 times, most recently from 8d344b5 to 1c02310 Compare October 11, 2023 13:43
@cleverchuk cleverchuk marked this pull request as ready for review October 11, 2023 14:34
@cleverchuk cleverchuk requested a review from a team as a code owner October 11, 2023 14:34
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.

Few comments below.

@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch from 33e527a to 07c9fca Compare October 12, 2023 12:33
@@ -5,6 +5,7 @@ plugins {
base.archivesName.set("${base.archivesName.get()}-autoconfigure")

dependencies {
implementation(project(":javaagent-bootstrap"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 Is this safe?

Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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) {      
    }

Copy link
Contributor

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

Copy link
Contributor Author

@cleverchuk cleverchuk Oct 20, 2023

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?

@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch from 1f02dc6 to 9527b78 Compare October 16, 2023 18:07
@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch 2 times, most recently from cd4020c to 6ec28c2 Compare October 17, 2023 17:35
@@ -25,6 +26,19 @@
* #supplyContextData()} is called when a log entry is created.
*/
public class OpenTelemetryContextDataProvider implements ContextDataProvider {

private boolean configuredResourceAttributeAccessible;
Copy link
Contributor

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

@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch from 6ec28c2 to 8653b1c Compare October 25, 2023 14:34

private static String[] getConfiguredAttributes() {
String resourceAttributes =
ConfigPropertiesUtil.getString("otel.instrumentation.mdc.resource-attributes");
Copy link
Contributor

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.

@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch from 80bea6d to 857db6e Compare October 26, 2023 18:26
@laurit
Copy link
Contributor

laurit commented Oct 31, 2023

@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.

@laurit
Copy link
Contributor

laurit commented Nov 7, 2023

@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
cleverchuk and others added 3 commits November 9, 2023 08:10
- move ConfiguredResourceAttributesHolder to javaagent-extension-api
@cleverchuk cleverchuk force-pushed the cc/add-config-based-mdc-attribute branch from 5fe7b75 to 4e80330 Compare November 9, 2023 13:13
@laurit
Copy link
Contributor

laurit commented Nov 13, 2023

@trask I added the docs, could you review

@trask
Copy link
Member

trask commented Nov 13, 2023

thx @laurit

wdyt of renaming

otel.instrumentation.mdc.resource-attributes

to

otel.instrumentation.common.mdc.resource-attributes

similar to discussion at #9758 (comment)?

@laurit
Copy link
Contributor

laurit commented Nov 13, 2023

@trask renamed

@trask trask merged commit 81f8bf6 into open-telemetry:main Nov 13, 2023
47 checks passed
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.

None yet

4 participants