From 2bff6634b4f5aa7ba65cfc118e88f5fd73c8c876 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 20 Oct 2022 16:19:53 -0700 Subject: [PATCH 1/4] Move more docs to docs folder --- docs/metrics/customizing-the-sdk/README.md | 2 +- docs/trace/customizing-the-sdk/README.md | 56 ++++++++++++++++++- .../ConsoleMetricExporter.cs | 9 ++- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/docs/metrics/customizing-the-sdk/README.md b/docs/metrics/customizing-the-sdk/README.md index d8a6a73fa9f..647a0cf95e4 100644 --- a/docs/metrics/customizing-the-sdk/README.md +++ b/docs/metrics/customizing-the-sdk/README.md @@ -446,8 +446,8 @@ The snippet below shows configuring the `Resource` associated with the provider. ```csharp using OpenTelemetry; -using OpenTelemetry.Resources; using OpenTelemetry.Metrics; +using OpenTelemetry.Resources; using var meterProvider = Sdk.CreateMeterProviderBuilder() .ConfigureResource(r => r.AddService("MyServiceName")) diff --git a/docs/trace/customizing-the-sdk/README.md b/docs/trace/customizing-the-sdk/README.md index 951e0dabffa..07ad1f0d4b0 100644 --- a/docs/trace/customizing-the-sdk/README.md +++ b/docs/trace/customizing-the-sdk/README.md @@ -199,11 +199,63 @@ logging, by supporting `Activity` and `LogRecord` respectively.* ### Resource -// TODO +[Resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md) +is the immutable representation of the entity producing the telemetry. If no +`Resource` is explicitly configured, the +[default](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value) +is to use a resource indicating this +[Service](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service). +The `ConfigureResource` method on `TracerProviderBuilder` can be used to set a +configure the resource on the provider. When the provider is built, it +automatically builds the final `Resource` from the configured `ResourceBuilder`. +There can only be a single `Resource` associated with a +provider. It is not possible to change the resource builder *after* the provider +is built, by calling the `Build()` method on the `TracerProviderBuilder`. +`ResourceBuilder` offers various methods to construct resource comprising of +multiple attributes from various sources. + +The snippet below shows configuring the `Resource` associated with the provider. + +```csharp +using OpenTelemetry; +using OpenTelemetry.Resources; +using OpenTelemetry.Trace; + +using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .ConfigureResource(r => r.AddService("MyServiceName")) + .Build(); +``` + +It is also possible to configure the `Resource` by using following +environmental variables: + +| Environment variable | Description | +| -------------------------- | -------------------------------------------------- | +| `OTEL_RESOURCE_ATTRIBUTES` | Key-value pairs to be used as resource attributes. See the [Resource SDK specification](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/resource/sdk.md#specifying-resource-information-via-an-environment-variable) for more details. | +| `OTEL_SERVICE_NAME` | Sets the value of the `service.name` resource attribute. If `service.name` is also provided in `OTEL_RESOURCE_ATTRIBUTES`, then `OTEL_SERVICE_NAME` takes precedence. | ### Sampler -// TODO +[Samplers](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk.md#sampler) +are used to control the noise and overhead introduced by OpenTelemetry by +reducing the number of samples of traces collected and sent to the processors. +If no sampler is explicitly configured, the default is to use +`ParentBased(root=AlwaysOn)`. `SetSampler` method on `TracerProviderBuilder` can +be used to set sampler. Only one sampler can be associated with a provider. If +multiple `SetSampler` is called, the last one wins. Also, it is not possible to +change the sampler *after* the provider is built, by calling the `Build()` +method on the `TracerProviderBuilder`. + +The snippet below shows configuring a custom sampler to the provider. + +```csharp +using OpenTelemetry; +using OpenTelemetry.Trace; + +using var tracerProvider = Sdk.CreateTracerProviderBuilder() + .SetSampler(new TraceIdRatioBasedSampler(0.25)) + .Build(); +``` ## Context Propagation diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs index 4826fedcd86..2424491b962 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs @@ -97,15 +97,14 @@ public override ExportResult Export(in Batch batch) var bucketsBuilder = new StringBuilder(); var sum = metricPoint.GetHistogramSum(); var count = metricPoint.GetHistogramCount(); + bucketsBuilder.Append($"Sum: {sum} Count: {count} "); if (metricPoint.HasMinMax()) { - bucketsBuilder.Append($"Sum: {sum} Count: {count} Min: {metricPoint.GetHistogramMin()} Max: {metricPoint.GetHistogramMax()} \n"); - } - else - { - bucketsBuilder.Append($"Sum: {sum} Count: {count} \n"); + bucketsBuilder.Append($"Min: {metricPoint.GetHistogramMin()} Max: {metricPoint.GetHistogramMax()} "); } + bucketsBuilder.Append("\n\r"); + bool isFirstIteration = true; double previousExplicitBound = default; foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets()) From 9745ac3585a40b2ca66cb1f79e3a260542daf602 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 20 Oct 2022 19:38:28 -0400 Subject: [PATCH 2/4] Update docs/trace/customizing-the-sdk/README.md Co-authored-by: Vishwesh Bankwar --- docs/trace/customizing-the-sdk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/trace/customizing-the-sdk/README.md b/docs/trace/customizing-the-sdk/README.md index 07ad1f0d4b0..98932eb6dd8 100644 --- a/docs/trace/customizing-the-sdk/README.md +++ b/docs/trace/customizing-the-sdk/README.md @@ -203,7 +203,7 @@ logging, by supporting `Activity` and `LogRecord` respectively.* is the immutable representation of the entity producing the telemetry. If no `Resource` is explicitly configured, the [default](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value) -is to use a resource indicating this +resource is used to indicate the [Service](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service). The `ConfigureResource` method on `TracerProviderBuilder` can be used to set a configure the resource on the provider. When the provider is built, it From 6e5b44a88c58739da11ef4e8e08f0a93fa891e01 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Thu, 20 Oct 2022 19:38:42 -0400 Subject: [PATCH 3/4] Update docs/trace/customizing-the-sdk/README.md Co-authored-by: Vishwesh Bankwar --- docs/trace/customizing-the-sdk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/trace/customizing-the-sdk/README.md b/docs/trace/customizing-the-sdk/README.md index 98932eb6dd8..e85207c8ea2 100644 --- a/docs/trace/customizing-the-sdk/README.md +++ b/docs/trace/customizing-the-sdk/README.md @@ -205,7 +205,7 @@ is the immutable representation of the entity producing the telemetry. If no [default](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#semantic-attributes-with-sdk-provided-default-value) resource is used to indicate the [Service](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md#service). -The `ConfigureResource` method on `TracerProviderBuilder` can be used to set a +The `ConfigureResource` method on `TracerProviderBuilder` can be used to configure the resource on the provider. When the provider is built, it automatically builds the final `Resource` from the configured `ResourceBuilder`. There can only be a single `Resource` associated with a From cb533be6c37e25b16fd86bfa3221a82e53d9a5bf Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Fri, 21 Oct 2022 09:37:31 -0700 Subject: [PATCH 4/4] silly me --- src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs index 2424491b962..3f4076b5f78 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs @@ -103,7 +103,7 @@ public override ExportResult Export(in Batch batch) bucketsBuilder.Append($"Min: {metricPoint.GetHistogramMin()} Max: {metricPoint.GetHistogramMax()} "); } - bucketsBuilder.Append("\n\r"); + bucketsBuilder.AppendLine(); bool isFirstIteration = true; double previousExplicitBound = default;