Search in sources :

Example 1 with ResourceBuilder

use of io.opentelemetry.sdk.resources.ResourceBuilder in project opentelemetry-plugin by jenkinsci.

the class OpenTelemetryConfiguration method toOpenTelemetryResource.

/**
 * @see io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder#addResourceCustomizer(BiFunction)
 */
@Nonnull
public Resource toOpenTelemetryResource() {
    ResourceBuilder resourceBuilder = Resource.builder();
    this.getServiceName().ifPresent(serviceName -> resourceBuilder.put(ResourceAttributes.SERVICE_NAME, serviceName));
    this.getServiceNamespace().ifPresent(serviceNamespace -> resourceBuilder.put(ResourceAttributes.SERVICE_NAMESPACE, serviceNamespace));
    resourceBuilder.put(JenkinsOtelSemanticAttributes.JENKINS_OPEN_TELEMETRY_PLUGIN_VERSION, OtelUtils.getOpentelemetryPluginVersion());
    return resourceBuilder.build();
}
Also used : ResourceBuilder(io.opentelemetry.sdk.resources.ResourceBuilder) Nonnull(javax.annotation.Nonnull)

Example 2 with ResourceBuilder

use of io.opentelemetry.sdk.resources.ResourceBuilder in project opentelemetry-plugin by jenkinsci.

the class OpenTelemetrySdkProvider method initialize.

public void initialize(@Nonnull OpenTelemetryConfiguration configuration) {
    // shutdown existing SDK
    preDestroy();
    AutoConfiguredOpenTelemetrySdkBuilder sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder();
    // PROPERTIES
    sdkBuilder.addPropertiesSupplier(() -> configuration.toOpenTelemetryProperties());
    // RESOURCE
    sdkBuilder.addResourceCustomizer((resource, configProperties) -> {
        ResourceBuilder resourceBuilder = Resource.builder().putAll(resource).putAll(configuration.toOpenTelemetryResource());
        return resourceBuilder.build();
    });
    sdkBuilder.registerShutdownHook(// SDK closed by io.jenkins.plugins.opentelemetry.OpenTelemetrySdkProvider.preDestroy()
    false).setResultAsGlobal(// ensure GlobalOpenTelemetry.set() is invoked
    true);
    AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk = sdkBuilder.build();
    this.openTelemetrySdk = autoConfiguredOpenTelemetrySdk.getOpenTelemetrySdk();
    this.resource = autoConfiguredOpenTelemetrySdk.getResource();
    this.config = autoConfiguredOpenTelemetrySdk.getConfig();
    this.openTelemetry = this.openTelemetrySdk;
    this.tracer.setDelegate(openTelemetry.getTracer(GlobalOpenTelemetrySdk.INSTRUMENTATION_NAME, OtelUtils.getOpentelemetryPluginVersion()));
    this.logEmitter = openTelemetrySdk.getSdkLogEmitterProvider().get(GlobalOpenTelemetrySdk.INSTRUMENTATION_NAME);
    this.meter = openTelemetry.getMeterProvider().get(GlobalOpenTelemetrySdk.INSTRUMENTATION_NAME);
    LOGGER.log(Level.INFO, () -> "OpenTelemetry SDK initialized: " + OtelUtils.prettyPrintOtelSdkConfig(autoConfiguredOpenTelemetrySdk));
}
Also used : AutoConfiguredOpenTelemetrySdkBuilder(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder) ResourceBuilder(io.opentelemetry.sdk.resources.ResourceBuilder) AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk)

Example 3 with ResourceBuilder

use of io.opentelemetry.sdk.resources.ResourceBuilder in project opentelemetry-java by open-telemetry.

the class ResourceConfiguration method filterAttributes.

// visible for testing
static Resource filterAttributes(Resource resource, ConfigProperties configProperties) {
    Set<String> disabledKeys = new HashSet<>(configProperties.getList(DISABLED_ATTRIBUTE_KEYS));
    Attributes filteredAttributes = resource.getAttributes().toBuilder().removeIf(attributeKey -> disabledKeys.contains(attributeKey.getKey())).build();
    ResourceBuilder builder = Resource.builder().putAll(filteredAttributes);
    if (resource.getSchemaUrl() != null) {
        builder.setSchemaUrl(resource.getSchemaUrl());
    }
    return builder.build();
}
Also used : ConfigProperties(io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties) HashSet(java.util.HashSet) ResourceProvider(io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider) ResourceBuilder(io.opentelemetry.sdk.resources.ResourceBuilder) Resource(io.opentelemetry.sdk.resources.Resource) BiFunction(java.util.function.BiFunction) Attributes(io.opentelemetry.api.common.Attributes) Set(java.util.Set) ServiceLoader(java.util.ServiceLoader) AttributesBuilder(io.opentelemetry.api.common.AttributesBuilder) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) ResourceBuilder(io.opentelemetry.sdk.resources.ResourceBuilder) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) HashSet(java.util.HashSet)

Example 4 with ResourceBuilder

use of io.opentelemetry.sdk.resources.ResourceBuilder in project opentelemetry-plugin by jenkinsci.

the class JenkinsResourceProvider method createResource.

@Override
public Resource createResource(ConfigProperties config) {
    ResourceBuilder resourceBuilder = Resource.builder();
    resourceBuilder.put(ResourceAttributes.SERVICE_NAME, JenkinsOtelSemanticAttributes.JENKINS);
    resourceBuilder.put(ResourceAttributes.SERVICE_NAMESPACE, JenkinsOtelSemanticAttributes.JENKINS);
    String jenkinsVersion = config.getString(JenkinsOtelSemanticAttributes.JENKINS_VERSION.getKey());
    // Allow service.version to be overwritten and also report jenkins.version
    resourceBuilder.put(ResourceAttributes.SERVICE_VERSION, jenkinsVersion);
    resourceBuilder.put(JenkinsOtelSemanticAttributes.JENKINS_VERSION.getKey(), jenkinsVersion);
    String jenkinsUrl = config.getString(JenkinsOtelSemanticAttributes.JENKINS_URL.getKey());
    resourceBuilder.put(JenkinsOtelSemanticAttributes.JENKINS_URL, jenkinsUrl);
    final Resource resource = resourceBuilder.build();
    LOGGER.log(Level.FINER, () -> "Jenkins resource: " + resource);
    return resource;
}
Also used : ResourceBuilder(io.opentelemetry.sdk.resources.ResourceBuilder) Resource(io.opentelemetry.sdk.resources.Resource)

Aggregations

ResourceBuilder (io.opentelemetry.sdk.resources.ResourceBuilder)4 Resource (io.opentelemetry.sdk.resources.Resource)2 Attributes (io.opentelemetry.api.common.Attributes)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 AutoConfiguredOpenTelemetrySdk (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk)1 AutoConfiguredOpenTelemetrySdkBuilder (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder)1 ConfigProperties (io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties)1 ResourceProvider (io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider)1 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)1 HashSet (java.util.HashSet)1 ServiceLoader (java.util.ServiceLoader)1 Set (java.util.Set)1 BiFunction (java.util.function.BiFunction)1 Nonnull (javax.annotation.Nonnull)1