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();
}
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));
}
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();
}
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;
}
Aggregations