Search in sources :

Example 6 with AutoConfiguredOpenTelemetrySdk

use of io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk in project opentelemetry-plugin by jenkinsci.

the class GlobalOpenTelemetrySdk method configure.

private static void configure(SdkConfigurationParameters newSdkConfigurationParameters, boolean registerShutDownHook) {
    Lock readLock = readWriteLock.readLock();
    readLock.lock();
    try {
        // VERIFY IF CONFIGURATION HAS CHANGED
        if (Objects.equals(newSdkConfigurationParameters, openTelemetrySdkState.getSdkConfigurationParameters())) {
            logger.log(Level.FINEST, () -> "OpenTelemetry SDK configuration has NOT changed, don't reinitialize SDK");
            return;
        }
    } finally {
        readLock.unlock();
    }
    Lock writeLock = readWriteLock.writeLock();
    writeLock.lock();
    try {
        if (Objects.equals(newSdkConfigurationParameters, openTelemetrySdkState.getSdkConfigurationParameters())) {
            logger.log(Level.FINEST, () -> "OpenTelemetry SDK configuration has NOT changed");
            return;
        }
        logger.log(Level.FINEST, () -> "Initialize/reinitialize OpenTelemetry SDK...");
        shutdown();
        final AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk = AutoConfiguredOpenTelemetrySdk.builder().addPropertiesSupplier(() -> newSdkConfigurationParameters.configurationProperties).addResourceCustomizer((resource, configProperties) -> {
            AttributesBuilder attributesBuilder = Attributes.builder();
            newSdkConfigurationParameters.resourceAttributes.forEach(attributesBuilder::put);
            return Resource.builder().putAll(resource).putAll(attributesBuilder.build()).build();
        }).registerShutdownHook(registerShutDownHook).build();
        openTelemetrySdkState = new OpenTelemetrySdkStateImpl(autoConfiguredOpenTelemetrySdk, newSdkConfigurationParameters);
        logger.log(Level.INFO, () -> "OpenTelemetry SDK initialized: " + OtelUtils.prettyPrintOtelSdkConfig(autoConfiguredOpenTelemetrySdk));
        configurationCounter.incrementAndGet();
    } finally {
        writeLock.unlock();
    }
}
Also used : AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 7 with AutoConfiguredOpenTelemetrySdk

use of io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk in project incubator-shenyu by apache.

the class OpenTelemetryAgentPluginBootService method start.

@Override
public void start(final AgentPluginConfig agentPluginConfig) {
    agentPluginConfig.getProps().forEach((key, value) -> System.setProperty(String.valueOf(key), String.valueOf(value)));
    AutoConfiguredOpenTelemetrySdk sdk = AutoConfiguredOpenTelemetrySdk.initialize();
    sdkTracerProvider = sdk.getOpenTelemetrySdk().getSdkTracerProvider();
}
Also used : AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk)

Aggregations

AutoConfiguredOpenTelemetrySdk (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk)7 Config (io.opentelemetry.instrumentation.api.config.Config)2 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)2 AutoConfiguredOpenTelemetrySdkBuilder (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder)2 ElasticsearchClient (co.elastic.clients.elasticsearch.ElasticsearchClient)1 FieldValue (co.elastic.clients.elasticsearch._types.FieldValue)1 SortOrder (co.elastic.clients.elasticsearch._types.SortOrder)1 SearchRequest (co.elastic.clients.elasticsearch.core.SearchRequest)1 SearchResponse (co.elastic.clients.elasticsearch.core.SearchResponse)1 Hit (co.elastic.clients.elasticsearch.core.search.Hit)1 JacksonJsonpMapper (co.elastic.clients.json.jackson.JacksonJsonpMapper)1 RestClientTransport (co.elastic.clients.transport.rest_client.RestClientTransport)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AutoService (com.google.auto.service.AutoService)1 Metrics (io.micrometer.core.instrument.Metrics)1 Tag (io.micrometer.core.instrument.Tag)1 Tags (io.micrometer.core.instrument.Tags)1 MeterFilter (io.micrometer.core.instrument.config.MeterFilter)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 AttributeKey (io.opentelemetry.api.common.AttributeKey)1