/// <summary> /// Adds service information to a <see cref="ResourceBuilder"/> /// following <a /// href="https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#service">semantic /// conventions</a>. /// </summary> /// <param name="resourceBuilder"><see cref="ResourceBuilder"/>.</param> /// <param name="serviceName">Name of the service.</param> /// <param name="serviceNamespace">Optional namespace of the service.</param> /// <param name="serviceVersion">Optional version of the service.</param> /// <param name="autoGenerateServiceInstanceId">Specify <see langword="true"/> to automatically generate a <see cref="Guid"/> for <paramref name="serviceInstanceId"/> if not supplied.</param> /// <param name="serviceInstanceId">Optional unique identifier of the service instance.</param> /// <returns>Returns <see cref="ResourceBuilder"/> for chaining.</returns> public static ResourceBuilder AddService( this ResourceBuilder resourceBuilder, string serviceName, string serviceNamespace = null, string serviceVersion = null, bool autoGenerateServiceInstanceId = true, string serviceInstanceId = null) { Dictionary <string, object> resourceAttributes = new Dictionary <string, object>(); Guard.ThrowIfNullOrEmpty(serviceName); resourceAttributes.Add(ResourceSemanticConventions.AttributeServiceName, serviceName); if (!string.IsNullOrEmpty(serviceNamespace)) { resourceAttributes.Add(ResourceSemanticConventions.AttributeServiceNamespace, serviceNamespace); } if (!string.IsNullOrEmpty(serviceVersion)) { resourceAttributes.Add(ResourceSemanticConventions.AttributeServiceVersion, serviceVersion); } if (serviceInstanceId == null && autoGenerateServiceInstanceId) { serviceInstanceId = Guid.NewGuid().ToString(); } if (serviceInstanceId != null) { resourceAttributes.Add(ResourceSemanticConventions.AttributeServiceInstance, serviceInstanceId); } return(resourceBuilder.AddResource(new Resource(resourceAttributes))); }
/// <summary> /// Adds service information to a <see cref="ResourceBuilder"/> /// following <a /// href="https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/resource/semantic_conventions#telemetry-sdk">semantic /// conventions</a>. /// </summary> /// <param name="resourceBuilder"><see cref="ResourceBuilder"/>.</param> /// <returns>Returns <see cref="ResourceBuilder"/> for chaining.</returns> public static ResourceBuilder AddTelemetrySdk(this ResourceBuilder resourceBuilder) { return(resourceBuilder.AddResource(TelemetryResource)); }
/// <summary> /// Adds resource attributes parsed from an environment variable to a /// <see cref="ResourceBuilder"/> following the <a /// href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable">Resource /// SDK</a>. /// </summary> /// <param name="resourceBuilder"><see cref="ResourceBuilder"/>.</param> /// <returns>Returns <see cref="ResourceBuilder"/> for chaining.</returns> public static ResourceBuilder AddEnvironmentVariableDetector(this ResourceBuilder resourceBuilder) { return(resourceBuilder.AddDetector(new OtelEnvResourceDetector())); }
/// <summary> /// Adds attributes to a <see cref="ResourceBuilder"/>. /// </summary> /// <param name="resourceBuilder"><see cref="ResourceBuilder"/>.</param> /// <param name="attributes">An <see cref="IEnumerable{T}"/> of attributes that describe the resource.</param> /// <returns>Returns <see cref="ResourceBuilder"/> for chaining.</returns> public static ResourceBuilder AddAttributes(this ResourceBuilder resourceBuilder, IEnumerable <KeyValuePair <string, object> > attributes) { return(resourceBuilder.AddResource(new Resource(attributes))); }