Skip to content

Commit 7f82b8d

Browse files
authored
Merge branch 'main' into mfogliatto/add-otlplogexporter-tests-2
2 parents 7ec6d9a + 7638d85 commit 7f82b8d

File tree

13 files changed

+115
-46
lines changed

13 files changed

+115
-46
lines changed

src/OpenTelemetry.Api/Internal/SemanticConventions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace OpenTelemetry.Trace
1818
{
1919
/// <summary>
2020
/// Constants for semantic attribute names outlined by the OpenTelemetry specifications.
21-
/// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/README.md"/>.
21+
/// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/README.md"/> and
22+
/// <see href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/README.md"/>.
2223
/// </summary>
2324
internal static class SemanticConventions
2425
{

src/OpenTelemetry.Instrumentation.Http/README.md

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ dotnet add package --prerelease OpenTelemetry.Instrumentation.Http
4040

4141
HTTP instrumentation must be enabled at application startup.
4242

43-
The following example demonstrates adding HTTP instrumentation to a console
44-
application. This example also sets up the OpenTelemetry Console exporter, which
45-
requires adding the package
43+
#### Traces
44+
45+
The following example demonstrates adding `HttpClient` instrumentation with the
46+
extension method `.AddHttpClientInstrumentation()` on `TracerProviderBuilder` to
47+
a console application. This example also sets up the OpenTelemetry Console
48+
Exporter, which requires adding the package
4649
[`OpenTelemetry.Exporter.Console`](../OpenTelemetry.Exporter.Console/README.md)
4750
to the application.
4851

@@ -62,13 +65,50 @@ public class Program
6265
}
6366
```
6467

65-
For an ASP.NET Core application, adding instrumentation is typically done in the
66-
`ConfigureServices` of your `Startup` class. Refer to documentation for
67-
[OpenTelemetry.Instrumentation.AspNetCore](../OpenTelemetry.Instrumentation.AspNetCore/README.md).
68+
#### Metrics
69+
70+
> **Note**
71+
> Metrics are not available for .NET Framework.
72+
73+
The following example demonstrates adding `HttpClient` instrumentation with the
74+
extension method `.AddHttpClientInstrumentation()` on `MeterProviderBuilder` to
75+
a console application. This example also sets up the OpenTelemetry Console
76+
Exporter, which requires adding the package
77+
[`OpenTelemetry.Exporter.Console`](../OpenTelemetry.Exporter.Console/README.md)
78+
to the application.
79+
80+
```csharp
81+
using OpenTelemetry;
82+
using OpenTelemetry.Metrics;
83+
84+
public class Program
85+
{
86+
public static void Main(string[] args)
87+
{
88+
using var meterProvider = Sdk.CreateMeterProviderBuilder()
89+
.AddHttpClientInstrumentation()
90+
.AddConsoleExporter()
91+
.Build();
92+
}
93+
}
94+
```
95+
96+
Refer to this [example](../../examples/AspNetCore/Program.cs) to see how to
97+
enable this instrumentation in an ASP.NET core application.
98+
99+
Refer to this
100+
[example](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.Instrumentation.AspNet/README.md)
101+
to see how to enable this instrumentation in an ASP.NET application.
102+
103+
#### List of metrics produced
104+
105+
The instrumentation was implemented based on [metrics semantic
106+
conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#metric-httpclientduration).
107+
Currently, the instrumentation supports the following metric.
68108

69-
For an ASP.NET application, adding instrumentation is typically done in the
70-
`Global.asax.cs`. Refer to the documentation for
71-
[OpenTelemetry.Instrumentation.AspNet](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.Instrumentation.AspNet/README.md).
109+
| Name | Instrument Type | Unit | Description |
110+
|-------|-----------------|------|-------------|
111+
| `http.client.duration` | Histogram | `ms` | Measures the duration of outbound HTTP requests. |
72112

73113
## Advanced configuration
74114

src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OpenTelemetry.Metrics.ExponentialHistogramData.NegativeBuckets.get -> OpenTeleme
2222
OpenTelemetry.Metrics.ExponentialHistogramData.PositiveBuckets.get -> OpenTelemetry.Metrics.ExponentialHistogramBuckets!
2323
OpenTelemetry.Metrics.ExponentialHistogramData.Scale.get -> int
2424
OpenTelemetry.Metrics.ExponentialHistogramData.ZeroCount.get -> long
25+
OpenTelemetry.Metrics.MetricType.ExponentialHistogram = 80 -> OpenTelemetry.Metrics.MetricType
2526
OpenTelemetry.Metrics.TraceBasedExemplarFilter
2627
OpenTelemetry.Metrics.TraceBasedExemplarFilter.TraceBasedExemplarFilter() -> void
2728
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.SetExemplarFilter(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, OpenTelemetry.Metrics.ExemplarFilter! exemplarFilter) -> OpenTelemetry.Metrics.MeterProviderBuilder!

src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OpenTelemetry.Metrics.ExponentialHistogramData.NegativeBuckets.get -> OpenTeleme
2222
OpenTelemetry.Metrics.ExponentialHistogramData.PositiveBuckets.get -> OpenTelemetry.Metrics.ExponentialHistogramBuckets!
2323
OpenTelemetry.Metrics.ExponentialHistogramData.Scale.get -> int
2424
OpenTelemetry.Metrics.ExponentialHistogramData.ZeroCount.get -> long
25+
OpenTelemetry.Metrics.MetricType.ExponentialHistogram = 80 -> OpenTelemetry.Metrics.MetricType
2526
OpenTelemetry.Metrics.TraceBasedExemplarFilter
2627
OpenTelemetry.Metrics.TraceBasedExemplarFilter.TraceBasedExemplarFilter() -> void
2728
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.SetExemplarFilter(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, OpenTelemetry.Metrics.ExemplarFilter! exemplarFilter) -> OpenTelemetry.Metrics.MeterProviderBuilder!

src/OpenTelemetry/.publicApi/netstandard2.0/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OpenTelemetry.Metrics.ExponentialHistogramData.NegativeBuckets.get -> OpenTeleme
2222
OpenTelemetry.Metrics.ExponentialHistogramData.PositiveBuckets.get -> OpenTelemetry.Metrics.ExponentialHistogramBuckets!
2323
OpenTelemetry.Metrics.ExponentialHistogramData.Scale.get -> int
2424
OpenTelemetry.Metrics.ExponentialHistogramData.ZeroCount.get -> long
25+
OpenTelemetry.Metrics.MetricType.ExponentialHistogram = 80 -> OpenTelemetry.Metrics.MetricType
2526
OpenTelemetry.Metrics.TraceBasedExemplarFilter
2627
OpenTelemetry.Metrics.TraceBasedExemplarFilter.TraceBasedExemplarFilter() -> void
2728
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.SetExemplarFilter(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, OpenTelemetry.Metrics.ExemplarFilter! exemplarFilter) -> OpenTelemetry.Metrics.MeterProviderBuilder!

src/OpenTelemetry/.publicApi/netstandard2.1/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OpenTelemetry.Metrics.ExponentialHistogramData.NegativeBuckets.get -> OpenTeleme
2222
OpenTelemetry.Metrics.ExponentialHistogramData.PositiveBuckets.get -> OpenTelemetry.Metrics.ExponentialHistogramBuckets!
2323
OpenTelemetry.Metrics.ExponentialHistogramData.Scale.get -> int
2424
OpenTelemetry.Metrics.ExponentialHistogramData.ZeroCount.get -> long
25+
OpenTelemetry.Metrics.MetricType.ExponentialHistogram = 80 -> OpenTelemetry.Metrics.MetricType
2526
OpenTelemetry.Metrics.TraceBasedExemplarFilter
2627
OpenTelemetry.Metrics.TraceBasedExemplarFilter.TraceBasedExemplarFilter() -> void
2728
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.SetExemplarFilter(this OpenTelemetry.Metrics.MeterProviderBuilder! meterProviderBuilder, OpenTelemetry.Metrics.ExemplarFilter! exemplarFilter) -> OpenTelemetry.Metrics.MeterProviderBuilder!

src/OpenTelemetry/BatchExportProcessor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected BatchExportProcessor(
8383
/// <summary>
8484
/// Gets the number of telemetry objects dropped by the processor.
8585
/// </summary>
86-
internal long DroppedCount => this.droppedCount;
86+
internal long DroppedCount => Volatile.Read(ref this.droppedCount);
8787

8888
/// <summary>
8989
/// Gets the number of telemetry objects received by the processor.
@@ -198,7 +198,7 @@ protected override bool OnForceFlush(int timeoutMilliseconds)
198198
return true;
199199
}
200200

201-
if (this.shutdownDrainTarget != long.MaxValue)
201+
if (Volatile.Read(ref this.shutdownDrainTarget) != long.MaxValue)
202202
{
203203
return false;
204204
}
@@ -208,7 +208,7 @@ protected override bool OnForceFlush(int timeoutMilliseconds)
208208
/// <inheritdoc/>
209209
protected override bool OnShutdown(int timeoutMilliseconds)
210210
{
211-
this.shutdownDrainTarget = this.circularBuffer.AddedCount;
211+
Volatile.Write(ref this.shutdownDrainTarget, this.circularBuffer.AddedCount);
212212

213213
try
214214
{
@@ -219,7 +219,7 @@ protected override bool OnShutdown(int timeoutMilliseconds)
219219
return false;
220220
}
221221

222-
OpenTelemetrySdkEventSource.Log.DroppedExportProcessorItems(this.GetType().Name, this.exporter.GetType().Name, this.droppedCount);
222+
OpenTelemetrySdkEventSource.Log.DroppedExportProcessorItems(this.GetType().Name, this.exporter.GetType().Name, this.DroppedCount);
223223

224224
if (timeoutMilliseconds == Timeout.Infinite)
225225
{
@@ -295,7 +295,7 @@ private void ExporterProc()
295295
}
296296
}
297297

298-
if (this.circularBuffer.RemovedCount >= this.shutdownDrainTarget)
298+
if (this.circularBuffer.RemovedCount >= Volatile.Read(ref this.shutdownDrainTarget))
299299
{
300300
return;
301301
}

src/OpenTelemetry/Metrics/AggregatorStore.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal sealed class AggregatorStore
3838
private readonly int[] currentMetricPointBatch;
3939
private readonly AggregationType aggType;
4040
private readonly double[] histogramBounds;
41-
private readonly int exponentialHistogramMaxBuckets;
41+
private readonly int exponentialHistogramMaxSize;
4242
private readonly UpdateLongDelegate updateLongCallback;
4343
private readonly UpdateDoubleDelegate updateDoubleCallback;
4444
private readonly int maxMetricPoints;
@@ -49,27 +49,24 @@ internal sealed class AggregatorStore
4949
private bool zeroTagMetricPointInitialized;
5050

5151
internal AggregatorStore(
52-
string name,
52+
MetricStreamIdentity metricStreamIdentity,
5353
AggregationType aggType,
5454
AggregationTemporality temporality,
5555
int maxMetricPoints,
56-
double[] histogramBounds,
57-
int exponentialHistogramMaxBuckets,
58-
string[] tagKeysInteresting = null,
5956
ExemplarFilter exemplarFilter = null)
6057
{
61-
this.name = name;
58+
this.name = metricStreamIdentity.InstrumentName;
6259
this.maxMetricPoints = maxMetricPoints;
6360
this.metricPointCapHitMessage = $"Maximum MetricPoints limit reached for this Metric stream. Configured limit: {this.maxMetricPoints}";
6461
this.metricPoints = new MetricPoint[maxMetricPoints];
6562
this.currentMetricPointBatch = new int[maxMetricPoints];
6663
this.aggType = aggType;
6764
this.outputDelta = temporality == AggregationTemporality.Delta;
68-
this.histogramBounds = histogramBounds;
69-
this.exponentialHistogramMaxBuckets = exponentialHistogramMaxBuckets;
65+
this.histogramBounds = metricStreamIdentity.HistogramBucketBounds ?? Metric.DefaultHistogramBounds;
66+
this.exponentialHistogramMaxSize = metricStreamIdentity.ExponentialHistogramMaxSize;
7067
this.StartTimeExclusive = DateTimeOffset.UtcNow;
7168
this.exemplarFilter = exemplarFilter ?? new AlwaysOffExemplarFilter();
72-
if (tagKeysInteresting == null)
69+
if (metricStreamIdentity.TagKeys == null)
7370
{
7471
this.updateLongCallback = this.UpdateLong;
7572
this.updateDoubleCallback = this.UpdateDouble;
@@ -78,7 +75,7 @@ internal AggregatorStore(
7875
{
7976
this.updateLongCallback = this.UpdateLongCustomTags;
8077
this.updateDoubleCallback = this.UpdateDoubleCustomTags;
81-
var hs = new HashSet<string>(tagKeysInteresting, StringComparer.Ordinal);
78+
var hs = new HashSet<string>(metricStreamIdentity.TagKeys, StringComparer.Ordinal);
8279
this.tagKeysInteresting = hs;
8380
this.tagsKeysInterestingCount = hs.Count;
8481
}
@@ -191,7 +188,7 @@ private void InitializeZeroTagPointIfNotInitialized()
191188
{
192189
if (!this.zeroTagMetricPointInitialized)
193190
{
194-
this.metricPoints[0] = new MetricPoint(this, this.aggType, null, this.histogramBounds, this.exponentialHistogramMaxBuckets);
191+
this.metricPoints[0] = new MetricPoint(this, this.aggType, null, this.histogramBounds, this.exponentialHistogramMaxSize);
195192
this.zeroTagMetricPointInitialized = true;
196193
}
197194
}
@@ -258,7 +255,7 @@ private int LookupAggregatorStore(KeyValuePair<string, object>[] tagKeysAndValue
258255
}
259256

260257
ref var metricPoint = ref this.metricPoints[aggregatorIndex];
261-
metricPoint = new MetricPoint(this, this.aggType, sortedTags.KeyValuePairs, this.histogramBounds, this.exponentialHistogramMaxBuckets);
258+
metricPoint = new MetricPoint(this, this.aggType, sortedTags.KeyValuePairs, this.histogramBounds, this.exponentialHistogramMaxSize);
262259

263260
// Add to dictionary *after* initializing MetricPoint
264261
// as other threads can start writing to the
@@ -307,7 +304,7 @@ private int LookupAggregatorStore(KeyValuePair<string, object>[] tagKeysAndValue
307304
}
308305

309306
ref var metricPoint = ref this.metricPoints[aggregatorIndex];
310-
metricPoint = new MetricPoint(this, this.aggType, givenTags.KeyValuePairs, this.histogramBounds, this.exponentialHistogramMaxBuckets);
307+
metricPoint = new MetricPoint(this, this.aggType, givenTags.KeyValuePairs, this.histogramBounds, this.exponentialHistogramMaxSize);
311308

312309
// Add to dictionary *after* initializing MetricPoint
313310
// as other threads can start writing to the

src/OpenTelemetry/Metrics/Metric.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ internal Metric(
3333
MetricStreamIdentity instrumentIdentity,
3434
AggregationTemporality temporality,
3535
int maxMetricPointsPerMetricStream,
36-
double[] histogramBounds = null,
37-
string[] tagKeysInteresting = null,
38-
bool histogramRecordMinMax = true,
3936
ExemplarFilter exemplarFilter = null)
4037
{
4138
this.InstrumentIdentity = instrumentIdentity;
@@ -118,18 +115,31 @@ internal Metric(
118115
|| instrumentIdentity.InstrumentType == typeof(Histogram<float>)
119116
|| instrumentIdentity.InstrumentType == typeof(Histogram<double>))
120117
{
121-
this.MetricType = MetricType.Histogram;
122-
123-
aggType = histogramBounds != null && histogramBounds.Length == 0
124-
? (histogramRecordMinMax ? AggregationType.HistogramWithMinMax : AggregationType.Histogram)
125-
: (histogramRecordMinMax ? AggregationType.HistogramWithMinMaxBuckets : AggregationType.HistogramWithBuckets);
118+
var explicitBucketBounds = instrumentIdentity.HistogramBucketBounds;
119+
var exponentialMaxSize = instrumentIdentity.ExponentialHistogramMaxSize;
120+
var histogramRecordMinMax = instrumentIdentity.HistogramRecordMinMax;
121+
122+
this.MetricType = exponentialMaxSize == 0
123+
? MetricType.Histogram
124+
: MetricType.ExponentialHistogram;
125+
126+
if (this.MetricType == MetricType.Histogram)
127+
{
128+
aggType = explicitBucketBounds != null && explicitBucketBounds.Length == 0
129+
? (histogramRecordMinMax ? AggregationType.HistogramWithMinMax : AggregationType.Histogram)
130+
: (histogramRecordMinMax ? AggregationType.HistogramWithMinMaxBuckets : AggregationType.HistogramWithBuckets);
131+
}
132+
else
133+
{
134+
aggType = histogramRecordMinMax ? AggregationType.Base2ExponentialHistogramWithMinMax : AggregationType.Base2ExponentialHistogram;
135+
}
126136
}
127137
else
128138
{
129139
throw new NotSupportedException($"Unsupported Instrument Type: {instrumentIdentity.InstrumentType.FullName}");
130140
}
131141

132-
this.aggStore = new AggregatorStore(instrumentIdentity.InstrumentName, aggType, temporality, maxMetricPointsPerMetricStream, histogramBounds ?? DefaultHistogramBounds, DefaultExponentialHistogramMaxBuckets, tagKeysInteresting, exemplarFilter);
142+
this.aggStore = new AggregatorStore(instrumentIdentity, aggType, temporality, maxMetricPointsPerMetricStream, exemplarFilter);
133143
this.Temporality = temporality;
134144
this.InstrumentDisposed = false;
135145
}

src/OpenTelemetry/Metrics/MetricReaderExt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ internal List<Metric> AddMetricsListWithViews(Instrument instrument, List<Metric
156156
}
157157
else
158158
{
159-
Metric metric = new(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream, metricStreamIdentity.HistogramBucketBounds, metricStreamIdentity.TagKeys, metricStreamIdentity.HistogramRecordMinMax, this.exemplarFilter);
159+
Metric metric = new(metricStreamIdentity, this.GetAggregationTemporality(metricStreamIdentity.InstrumentType), this.maxMetricPointsPerMetricStream, this.exemplarFilter);
160160

161161
this.instrumentIdentityToMetric[metricStreamIdentity] = metric;
162162
this.metrics[index] = metric;

0 commit comments

Comments
 (0)