Reputation: 19
I have test java app with java agent opentelemetry instrumentation: -javaagent:/usr/src/app/opentelemetry-javaagent.jar -Dotel.instrumentation.log4j-context-data.enabled=true -Dotel.instrumentation.log4j-appender.enabled=true -Dotel.instrumentation.log4j-appender.experimental.capture-mdc-attributes=*
And I have logs:
{
"resourceLogs" : [
{
"resource" : {
"attributes" : [
{
"key" : "container.id",
"value" : {
"stringValue" : "97dc4496d3a0573ca8264184162c7870122daa52aba1d8d76578ee93135f31eb"
}
},
{
"key" : "host.arch",
"value" : {
"stringValue" : "amd64"
}
},
{
"key" : "host.name",
"value" : {
"stringValue" : "97dc4496d3a0"
}
},
{
"key" : "k8s.namespace.name",
"value" : {
"stringValue" : "name-space"
}
},
{
"key" : "os.description",
"value" : {
"stringValue" : "Linux 5.15.150.1-microsoft-standard-WSL2"
}
},
{
"key" : "os.type",
"value" : {
"stringValue" : "linux"
}
},
{
"key" : "process.command_line",
"value" : {
"stringValue" : "/opt/java/openjdk/bin/java -javaagent:/usr/src/app/opentelemetry-javaagent.jar -Dotel.instrumentation.log4j-context-data.enabled=true -Dotel.instrumentation.log4j-appender.enabled=true -Dotel.instrumentation.log4j-appender.experimental.capture-mdc-attributes=* oteldemo.Service"
}
},
{
"key" : "process.executable.path",
"value" : {
"stringValue" : "/opt/java/openjdk/bin/java"
}
},
{
"key" : "process.pid",
"value" : {
"intValue" : "1"
}
},
{
"key" : "process.runtime.description",
"value" : {
"stringValue" : "Eclipse Adoptium OpenJDK 64-Bit Server VM 21.0.4+7-LTS"
}
},
{
"key" : "process.runtime.name",
"value" : {
"stringValue" : "OpenJDK Runtime Environment"
}
},
{
"key" : "process.runtime.version",
"value" : {
"stringValue" : "21.0.4+7-LTS"
}
},
{
"key" : "service.instance.id",
"value" : {
"stringValue" : "1a4d8792-2b25-4524-ab33-4d1029939db8"
}
},
{
"key" : "service.name",
"value" : {
"stringValue" : "service"
}
},
{
"key" : "telemetry.distro.name",
"value" : {
"stringValue" : "opentelemetry-java-instrumentation"
}
},
{
"key" : "telemetry.distro.version",
"value" : {
"stringValue" : "2.3.0"
}
},
{
"key" : "telemetry.sdk.language",
"value" : {
"stringValue" : "java"
}
},
{
"key" : "telemetry.sdk.name",
"value" : {
"stringValue" : "opentelemetry"
}
},
{
"key" : "telemetry.sdk.version",
"value" : {
"stringValue" : "1.37.0"
}
}
]
},
"scopeLogs" : [
{
"scope" : {
"name" : "oteldemo.Service"
},
"logRecords" : [
{
"timeUnixNano" : "1727765793069162445",
"observedTimeUnixNano" : "1727765793069195376",
"severityNumber" : 9,
"severityText" : "INFO",
"body" : {
"stringValue" : "Service starting."
},
"attributes" : [
],
"traceId" : "",
"spanId" : ""
}
]
}
],
"schemaUrl" : "https://opentelemetry.io/schemas/1.24.0"
}
]
}
I need to add to log fields callerClass
, callerLine
, threadName
and others which I can insert to the log4j appender using JsonTemplateLayout
, for example:
"threadName": {
"$resolver": "thread",
"field": "name"
},
"callerClass": {
"$resolver": "source",
"field": "className"
},
"callerMethod": {
"$resolver": "source",
"field": "methodName"
},
"callerLine": {
"$resolver": "source",
"field": "lineNumber"
}
How to do the same using Java agent OpenTelemetry instrumentation (embedded OpenTelemetry appender)?
Upvotes: 1
Views: 77