-
Hi everyone, I'm experimenting with the logging SDK, however I'm getting stuck when I need to pass particular attributes to my logs. I can't find how to do it in the documentation. Here is my configuration: @Bean
public SdkLoggerProvider sdkLoggerProvider(){
Resource resource = Resource.getDefault()
.merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "Admin Service")));
LogRecordExporter logRecordExporter = OtlpHttpLogRecordExporter.builder()
.setEndpoint("https://my-open-telemetry-endpoint.com"+"/v1/logs")
.build();
SdkLoggerProvider sdkLoggerProvider = SdkLoggerProvider.builder()
.addLogRecordProcessor(BatchLogRecordProcessor.builder(logRecordExporter).build())
.setResource(resource)
.build();
GlobalLoggerProvider.set(sdkLoggerProvider);
return sdkLoggerProvider;
} @Bean
public OpenTelemetry openTelemetry(SdkLoggerProvider sdkLoggerProvider) throws IOException {
Resource resource = Resource.getDefault()
.merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "Admin Service")));
// trace config
SpanExporter spanExporter = OtlpHttpSpanExporter.builder()
.setEndpoint("https://my-open-telemetry-endpoint.com"+"/v1/traces")
.build();
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(spanExporter).build())
.setResource(resource)
.build();
OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
.setLoggerProvider(sdkLoggerProvider)
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
.buildAndRegisterGlobal();
return openTelemetry;
} I use the classic: log.error("My message") and that work properly but how to add specific attributes ? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I think u can use Attribute builder to add attributes.
perhaps it may help you somehow. |
Beta Was this translation helpful? Give feedback.
-
I found the solution, i need to use the logger
.eventBuilder(reason)
.setBody("Error in function: "+functionName+" with this reason: "+reason)
.setSeverity(Severity.ERROR)
.setAttribute(AttributeKey.stringKey("requestId"),requestId) and then emit it |
Beta Was this translation helpful? Give feedback.
-
Please note: these APIs are not stable. We will be changing them, and we do not intend the logging APIs to be used by end users, only by people writing appenders for other logging frameworks. The logging APIs that we build will not be optimized for end users for that reason. |
Beta Was this translation helpful? Give feedback.
I found the solution, i need to use the
LogRecordBuilder
:and then emit it