-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWireUp.java
55 lines (44 loc) · 2.11 KB
/
WireUp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.example.opentelemetry;
import io.micronaut.runtime.event.annotation.EventListener;
import io.micronaut.runtime.server.event.ServerStartupEvent;
import io.opentelemetry.exporter.internal.retry.RetryPolicy;
import io.opentelemetry.exporter.internal.retry.RetryUtil;
import io.opentelemetry.exporter.otlp.logs.OtlpGrpcLogExporter;
import io.opentelemetry.instrumentation.logback.appender.v1_0.OpenTelemetryAppender;
import io.opentelemetry.sdk.logs.LogLimits;
import io.opentelemetry.sdk.logs.SdkLogEmitterProvider;
import io.opentelemetry.sdk.logs.export.BatchLogProcessor;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.AllArgsConstructor;
@Singleton
@AllArgsConstructor
public class WireUp {
@Inject
private final LoggingConfig config;
@EventListener
void startupHandler(ServerStartupEvent event) {
addLoggingExporter(config);
}
public static void addLoggingExporter(LoggingConfig config) {
var resource = Resource.getDefault().toBuilder()
.put(ResourceAttributes.SERVICE_NAME, config.getName())
.put(ResourceAttributes.SERVICE_INSTANCE_ID, config.getInstance())
.build();
var logExporterBuilder =
OtlpGrpcLogExporter.builder()
.setEndpoint(config.getEndpoint())
.setCompression("gzip")
.addHeader("api-key", config.getKey());
RetryUtil.setRetryPolicyOnDelegate(logExporterBuilder, RetryPolicy.getDefault());
SdkLogEmitterProvider logEmitterProvider =
SdkLogEmitterProvider.builder()
.setResource(resource)
.setLogLimits(() -> LogLimits.getDefault().toBuilder().setMaxAttributeValueLength(4095).build())
.addLogProcessor(BatchLogProcessor.builder(logExporterBuilder.build()).build())
.build();
OpenTelemetryAppender.setSdkLogEmitterProvider(logEmitterProvider);
}
}