Skip to content

Commit

Permalink
Merge branch 'main' into vibankwa/change-enrich-filter-aspnetcore
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Oct 21, 2022
2 parents c1cbbad + f94ccb7 commit bd814f1
Show file tree
Hide file tree
Showing 42 changed files with 99 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/metrics/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
56 changes: 54 additions & 2 deletions docs/trace/customizing-the-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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
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

Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Api/Baggage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private static BaggageHolder EnsureBaggageHolder()
return baggageHolder;
}

private class BaggageHolder
private sealed class BaggageHolder
{
public Baggage Baggage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Internal
/// This is used for internal logging of this library.
/// </summary>
[EventSource(Name = "OpenTelemetry-Api")]
internal class OpenTelemetryApiEventSource : EventSource
internal sealed class OpenTelemetryApiEventSource : EventSource
{
public static OpenTelemetryApiEventSource Log = new();

Expand Down
9 changes: 4 additions & 5 deletions src/OpenTelemetry.Exporter.Console/ConsoleMetricExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,14 @@ public override ExportResult Export(in Batch<Metric> 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.AppendLine();

bool isFirstIteration = true;
double previousExplicitBound = default;
foreach (var histogramMeasurement in metricPoint.GetHistogramBuckets())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/> (Turns off StyleCop analysis in this file.)
// <auto-generated/> (Turns off StyleCop analysis in this file.)

// Licensed to the Apache Software Foundation(ASF) under one
// or more contributor license agreements.See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/> (Turns off StyleCop analysis in this file.)
// <auto-generated/> (Turns off StyleCop analysis in this file.)

// Licensed to the Apache Software Foundation(ASF) under one
// or more contributor license agreements.See the NOTICE file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Exporter.Jaeger.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Exporter-Jaeger")]
internal class JaegerExporterEventSource : EventSource
internal sealed class JaegerExporterEventSource : EventSource
{
public static JaegerExporterEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace OpenTelemetry.Exporter.OpenTelemetryProtocol.Implementation
{
[EventSource(Name = "OpenTelemetry-Exporter-OpenTelemetryProtocol")]
internal class OpenTelemetryProtocolExporterEventSource : EventSource
internal sealed class OpenTelemetryProtocolExporterEventSource : EventSource
{
public static readonly OpenTelemetryProtocolExporterEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace OpenTelemetry.Exporter
/// Exporter consuming <see cref="LogRecord"/> and exporting the data using
/// the OpenTelemetry protocol (OTLP).
/// </summary>
internal class OtlpLogExporter : BaseExporter<LogRecord>
internal sealed class OtlpLogExporter : BaseExporter<LogRecord>
{
private readonly SdkLimitOptions sdkLimitOptions;
private readonly IExportClient<OtlpCollector.ExportLogsServiceRequest> exportClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace OpenTelemetry.Exporter.ZPages.Implementation
/// <summary>
/// Stores the activity information aggregated according to activity name.
/// </summary>
internal class ZPagesActivityAggregate
internal sealed class ZPagesActivityAggregate
{
/// <summary>
/// Initializes a new instance of the <see cref="ZPagesActivityAggregate"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Exporter.ZPages.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Exporter-ZPages")]
internal class ZPagesExporterEventSource : EventSource
internal sealed class ZPagesExporterEventSource : EventSource
{
public static ZPagesExporterEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace OpenTelemetry.Exporter.ZPages.Implementation
{
internal class ZPagesStatsBuilder
internal sealed class ZPagesStatsBuilder
{
public const string ContentType = "text/html";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace OpenTelemetry.Exporter.Zipkin.Implementation
{
internal class ZipkinEndpoint
internal sealed class ZipkinEndpoint
{
public ZipkinEndpoint(string serviceName)
: this(serviceName, null, null, null, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Exporter.Zipkin.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Exporter-Zipkin")]
internal class ZipkinExporterEventSource : EventSource
internal sealed class ZipkinExporterEventSource : EventSource
{
public static ZipkinExporterEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Extensions.Hosting.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Extensions-Hosting")]
internal class HostingExtensionsEventSource : EventSource
internal sealed class HostingExtensionsEventSource : EventSource
{
public static HostingExtensionsEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Internal
/// This is used for internal logging of this library.
/// </summary>
[EventSource(Name = "OpenTelemetry.Extensions.Propagators")]
internal class OpenTelemetryPropagatorsEventSource : EventSource
internal sealed class OpenTelemetryPropagatorsEventSource : EventSource
{
public static OpenTelemetryPropagatorsEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore
/// <summary>
/// Asp.Net Core Requests instrumentation.
/// </summary>
internal class AspNetCoreInstrumentation : IDisposable
internal sealed class AspNetCoreInstrumentation : IDisposable
{
private static readonly HashSet<string> DiagnosticSourceEvents = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore
/// <summary>
/// Asp.Net Core Requests instrumentation.
/// </summary>
internal class AspNetCoreMetrics : IDisposable
internal sealed class AspNetCoreMetrics : IDisposable
{
internal static readonly AssemblyName AssemblyName = typeof(HttpInListener).Assembly.GetName();
internal static readonly string InstrumentationName = AssemblyName.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Instrumentation-AspNetCore")]
internal class AspNetCoreInstrumentationEventSource : EventSource
internal sealed class AspNetCoreInstrumentationEventSource : EventSource
{
public static AspNetCoreInstrumentationEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace OpenTelemetry.Instrumentation.AspNetCore.Implementation
{
internal class HttpInMetricsListener : ListenerHandler
internal sealed class HttpInMetricsListener : ListenerHandler
{
private const string OnStopEvent = "Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenTelemetry.Instrumentation.GrpcNetClient
/// <summary>
/// GrpcClient instrumentation.
/// </summary>
internal class GrpcClientInstrumentation : IDisposable
internal sealed class GrpcClientInstrumentation : IDisposable
{
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Instrumentation-Grpc")]
internal class GrpcInstrumentationEventSource : EventSource
internal sealed class GrpcInstrumentationEventSource : EventSource
{
public static GrpcInstrumentationEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenTelemetry.Instrumentation.Http
/// <summary>
/// HttpClient instrumentation.
/// </summary>
internal class HttpClientInstrumentation : IDisposable
internal sealed class HttpClientInstrumentation : IDisposable
{
private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation.Http
/// <summary>
/// HttpClient instrumentation.
/// </summary>
internal class HttpClientMetrics : IDisposable
internal sealed class HttpClientMetrics : IDisposable
{
internal static readonly AssemblyName AssemblyName = typeof(HttpClientMetrics).Assembly.GetName();
internal static readonly string InstrumentationName = AssemblyName.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace OpenTelemetry.Instrumentation.Http.Implementation
{
internal class HttpHandlerMetricsDiagnosticListener : ListenerHandler
internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
{
internal const string OnStopEvent = "System.Net.Http.HttpRequestOut.Stop";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation.Http.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Instrumentation-Http")]
internal class HttpInstrumentationEventSource : EventSource
internal sealed class HttpInstrumentationEventSource : EventSource
{
public static HttpInstrumentationEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
/// Helper class to hold common properties used by both SqlClientDiagnosticListener on .NET Core
/// and SqlEventSourceListener on .NET Framework.
/// </summary>
internal class SqlActivitySourceHelper
internal sealed class SqlActivitySourceHelper
{
public const string MicrosoftSqlServerDatabaseSystemName = "mssql";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient.Implementation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Instrumentation-SqlClient")]
internal class SqlClientInstrumentationEventSource : EventSource
internal sealed class SqlClientInstrumentationEventSource : EventSource
{
public static SqlClientInstrumentationEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient
/// <summary>
/// SqlClient instrumentation.
/// </summary>
internal class SqlClientInstrumentation : IDisposable
internal sealed class SqlClientInstrumentation : IDisposable
{
internal const string SqlClientDiagnosticListenerName = "SqlClientDiagnosticListener";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ internal void AddConnectionLevelDetailsToActivity(string dataSource, Activity sq
}
}

internal class SqlConnectionDetails
internal sealed class SqlConnectionDetails
{
public string ServerHostName { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry.Shims.OpenTracing/ScopeManagerShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public IScope Activate(ISpan span, bool finishSpanOnDispose)
return instrumentation;
}

private class ScopeInstrumentation : IScope
private sealed class ScopeInstrumentation : IScope
{
private readonly Action disposeAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OpenTelemetry.Instrumentation
{
internal class DiagnosticSourceListener : IObserver<KeyValuePair<string, object>>
internal sealed class DiagnosticSourceListener : IObserver<KeyValuePair<string, object>>
{
private readonly ListenerHandler handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace OpenTelemetry.Instrumentation
/// EventSource events emitted from the project.
/// </summary>
[EventSource(Name = "OpenTelemetry-Instrumentation")]
internal class InstrumentationEventSource : EventSource
internal sealed class InstrumentationEventSource : EventSource
{
public static InstrumentationEventSource Log = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace OpenTelemetry.Instrumentation
/// PropertyFetcher fetches a property from an object.
/// </summary>
/// <typeparam name="T">The type of the property being fetched.</typeparam>
internal class PropertyFetcher<T>
internal sealed class PropertyFetcher<T>
{
private readonly string propertyName;
private PropertyFetch innerFetcher;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace OpenTelemetry.Internal
/// EventSource implementation for OpenTelemetry SDK implementation.
/// </summary>
[EventSource(Name = "OpenTelemetry-Sdk")]
internal class OpenTelemetrySdkEventSource : EventSource
internal sealed class OpenTelemetrySdkEventSource : EventSource
{
public static OpenTelemetrySdkEventSource Log = new();
#if DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Internal/SelfDiagnosticsConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace OpenTelemetry.Internal
{
internal class SelfDiagnosticsConfigParser
internal sealed class SelfDiagnosticsConfigParser
{
public const string ConfigFileName = "OTEL_DIAGNOSTICS.json";
private const int FileSizeLowerLimit = 1024; // Lower limit for log file size in KB: 1MB
Expand Down
Loading

0 comments on commit bd814f1

Please sign in to comment.