[Instrumentation.Http] follow up from previous pr (#4919)
This commit is contained in:
parent
c2293e088e
commit
be45aab2ba
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
* Introduced a new metric, `http.client.request.duration` measured in seconds.
|
||||
The OTel SDK
|
||||
* Introduced a new metric for `HttpClient`, `http.client.request.duration`
|
||||
measured in seconds. The OTel SDK
|
||||
[applies custom histogram buckets](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4820)
|
||||
for this metric to comply with the
|
||||
[Semantic Convention for Http Metrics](https://github.com/open-telemetry/semantic-conventions/blob/2bad9afad58fbd6b33cc683d1ad1f006e35e4a5d/docs/http/http-metrics.md).
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
* [http-metrics](https://github.com/open-telemetry/semantic-conventions/blob/2bad9afad58fbd6b33cc683d1ad1f006e35e4a5d/docs/http/http-metrics.md)
|
||||
|
||||
* Added support for publishing `http.client.duration` &
|
||||
`http.client.request.duration` metrics on .NET Framework
|
||||
`http.client.request.duration` metrics on .NET Framework for `HttpWebRequest`.
|
||||
([#4870](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4870))
|
||||
|
||||
## 1.5.1-beta.1
|
||||
|
|
|
|||
|
|
@ -99,14 +99,32 @@ to see how to enable this instrumentation in an ASP.NET application.
|
|||
|
||||
#### List of metrics produced
|
||||
|
||||
The instrumentation is implemented based on [metrics semantic
|
||||
conventions](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#metric-httpclientduration).
|
||||
Currently, the instrumentation supports the following metric.
|
||||
A different metric is emitted depending on whether a user opts-in to the new
|
||||
Http Semantic Conventions using `OTEL_SEMCONV_STABILITY_OPT_IN`.
|
||||
|
||||
* By default, the instrumentation emits the following metric.
|
||||
|
||||
| Name | Instrument Type | Unit | Description |
|
||||
|-------|-----------------|------|-------------|
|
||||
| `http.client.duration` | Histogram | `ms` | Measures the duration of outbound HTTP requests. |
|
||||
|
||||
* If user sets the environment variable to `http`, the instrumentation emits
|
||||
the following metric.
|
||||
|
||||
| Name | Instrument Type | Unit | Description |
|
||||
|-------|-----------------|------|-------------|
|
||||
| `http.client.request.duration` | Histogram | `s` | Measures the duration of outbound HTTP requests. |
|
||||
|
||||
This metric is emitted in `seconds` as per the semantic convention. While
|
||||
the convention [recommends using custom histogram buckets](https://github.com/open-telemetry/semantic-conventions/blob/2bad9afad58fbd6b33cc683d1ad1f006e35e4a5d/docs/http/http-metrics.md)
|
||||
, this feature is not yet available via .NET Metrics API.
|
||||
A [workaround](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4820)
|
||||
has been included in OTel SDK starting version `1.6.0` which applies
|
||||
recommended buckets by default for `http.client.request.duration`.
|
||||
|
||||
* If user sets the environment variable to `http/dup`, the instrumentation
|
||||
emits both `http.client.duration` and `http.client.request.duration`.
|
||||
|
||||
## Advanced configuration
|
||||
|
||||
This instrumentation can be configured to change the default behavior by using
|
||||
|
|
|
|||
|
|
@ -355,6 +355,7 @@ public partial class HttpClientTests
|
|||
{
|
||||
var metric = requestMetrics.FirstOrDefault(m => m.Name == "http.client.duration");
|
||||
Assert.NotNull(metric);
|
||||
Assert.Equal("ms", metric.Unit);
|
||||
Assert.True(metric.MetricType == MetricType.Histogram);
|
||||
|
||||
var metricPoints = new List<MetricPoint>();
|
||||
|
|
@ -381,6 +382,7 @@ public partial class HttpClientTests
|
|||
Assert.True(sum > 0);
|
||||
}
|
||||
|
||||
// Inspect Metric Attributes
|
||||
var attributes = new Dictionary<string, object>();
|
||||
foreach (var tag in metricPoint.Tags)
|
||||
{
|
||||
|
|
@ -391,8 +393,6 @@ public partial class HttpClientTests
|
|||
|
||||
Assert.Equal(expectedAttributeCount, attributes.Count);
|
||||
|
||||
if (semanticConvention == null || semanticConvention.Value.HasFlag(HttpSemanticConvention.Old))
|
||||
{
|
||||
Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeHttpMethod && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeHttpMethod]);
|
||||
Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeNetPeerName && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeNetPeerName]);
|
||||
Assert.Contains(attributes, kvp => kvp.Key == SemanticConventions.AttributeNetPeerPort && kvp.Value.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeNetPeerPort]);
|
||||
|
|
@ -406,13 +406,25 @@ public partial class HttpClientTests
|
|||
{
|
||||
Assert.DoesNotContain(attributes, kvp => kvp.Key == SemanticConventions.AttributeHttpStatusCode);
|
||||
}
|
||||
|
||||
// Inspect Histogram Bounds
|
||||
var histogramBuckets = metricPoint.GetHistogramBuckets();
|
||||
var histogramBounds = new List<double>();
|
||||
foreach (var t in histogramBuckets)
|
||||
{
|
||||
histogramBounds.Add(t.ExplicitBound);
|
||||
}
|
||||
|
||||
Assert.Equal(
|
||||
expected: new List<double> { 0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000, double.PositiveInfinity },
|
||||
actual: histogramBounds);
|
||||
}
|
||||
|
||||
if (semanticConvention != null && semanticConvention.Value.HasFlag(HttpSemanticConvention.New))
|
||||
{
|
||||
var metric = requestMetrics.FirstOrDefault(m => m.Name == "http.client.request.duration");
|
||||
Assert.NotNull(metric);
|
||||
Assert.Equal("s", metric.Unit);
|
||||
Assert.True(metric.MetricType == MetricType.Histogram);
|
||||
|
||||
var metricPoints = new List<MetricPoint>();
|
||||
|
|
@ -439,6 +451,7 @@ public partial class HttpClientTests
|
|||
Assert.True(sum > 0);
|
||||
}
|
||||
|
||||
// Inspect Metric Attributes
|
||||
var attributes = new Dictionary<string, object>();
|
||||
foreach (var tag in metricPoint.Tags)
|
||||
{
|
||||
|
|
@ -461,6 +474,18 @@ public partial class HttpClientTests
|
|||
{
|
||||
Assert.DoesNotContain(attributes, kvp => kvp.Key == SemanticConventions.AttributeHttpResponseStatusCode);
|
||||
}
|
||||
|
||||
// Inspect Histogram Bounds
|
||||
var histogramBuckets = metricPoint.GetHistogramBuckets();
|
||||
var histogramBounds = new List<double>();
|
||||
foreach (var t in histogramBuckets)
|
||||
{
|
||||
histogramBounds.Add(t.ExplicitBound);
|
||||
}
|
||||
|
||||
Assert.Equal(
|
||||
expected: new List<double> { 0, 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10, double.PositiveInfinity },
|
||||
actual: histogramBounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue