Skip to content

Commit

Permalink
Merge branch 'main' into hist-binary
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Sep 2, 2022
2 parents 9a3025c + db0918e commit 2bb1212
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"appsettings",
"asax",
"cijo",
"cncf",
Expand Down Expand Up @@ -37,8 +38,8 @@
"struct",
"tbody",
"thead",
"Tracestate",
"tracestate",
"Tracestate",
"triager",
"umesan",
"unencrypted",
Expand Down
6 changes: 4 additions & 2 deletions examples/AspNetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// OpenTelemetry
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";

// Switch between Zipkin/Jaeger/OTLP by setting UseExporter in appsettings.json.
// Switch between Zipkin/Jaeger/OTLP/Console by setting UseTracingExporter in appsettings.json.
var tracingExporter = builder.Configuration.GetValue<string>("UseTracingExporter").ToLowerInvariant();

var serviceName = tracingExporter switch
Expand Down Expand Up @@ -90,6 +90,8 @@
builder.Logging.AddOpenTelemetry(options =>
{
options.ConfigureResource(configureResource);

// Switch between Console/OTLP by setting UseLogExporter in appsettings.json.
var logExporter = builder.Configuration.GetValue<string>("UseLogExporter").ToLowerInvariant();
switch (logExporter)
{
Expand All @@ -113,7 +115,7 @@
});

// Metrics

// Switch between Prometheus/OTLP/Console by setting UseMetricsExporter in appsettings.json.
var metricsExporter = builder.Configuration.GetValue<string>("UseMetricsExporter").ToLowerInvariant();

builder.Services.AddOpenTelemetryMetrics(options =>
Expand Down
3 changes: 0 additions & 3 deletions examples/AspNetCore/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
"Endpoint": "http://localhost:14268",
"Protocol": "UdpCompactThrift"
},
"Prometheus": {
"ScrapeResponseCacheDurationMilliseconds": 5000
},
"Zipkin": {
"ServiceName": "zipkin-test",
"Endpoint": "http://localhost:9411/api/v2/spans"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
override OpenTelemetry.Exporter.ConsoleLogRecordExporter.Dispose(bool disposing) -> void
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Changed the behavior of `ConsoleExporter`, the exporter will stop outputting
the data if it is disposed.
([#3578](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3578))

## 1.4.0-alpha.2

Released 2022-Aug-18
Expand Down
39 changes: 39 additions & 0 deletions src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

using System;
using System.Collections.Generic;
using OpenTelemetry.Logs;
using OpenTelemetry.Resources;
Expand All @@ -23,6 +24,10 @@ namespace OpenTelemetry.Exporter
public class ConsoleLogRecordExporter : ConsoleExporter<LogRecord>
{
private const int RightPaddingLength = 35;
private readonly object syncObject = new();
private bool disposed;
private string disposedStackTrace;
private bool isDisposeMessageSent;

public ConsoleLogRecordExporter(ConsoleExporterOptions options)
: base(options)
Expand All @@ -31,6 +36,29 @@ public ConsoleLogRecordExporter(ConsoleExporterOptions options)

public override ExportResult Export(in Batch<LogRecord> batch)
{
if (this.disposed)
{
if (!this.isDisposeMessageSent)
{
lock (this.syncObject)
{
if (this.isDisposeMessageSent)
{
return ExportResult.Failure;
}

this.isDisposeMessageSent = true;
}

this.WriteLine("The console exporter is still being invoked after it has been disposed. This could be due to the application's incorrect lifecycle management of the LoggerFactory/OpenTelemetry .NET SDK.");
this.WriteLine(Environment.StackTrace);
this.WriteLine(Environment.NewLine + "Dispose was called on the following stack trace:");
this.WriteLine(this.disposedStackTrace);
}

return ExportResult.Failure;
}

foreach (var logRecord in batch)
{
this.WriteLine($"{"LogRecord.Timestamp:",-RightPaddingLength}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}");
Expand Down Expand Up @@ -129,5 +157,16 @@ void ProcessScope(LogRecordScope scope, ConsoleLogRecordExporter exporter)

return ExportResult.Success;
}

protected override void Dispose(bool disposing)
{
if (!this.disposed)
{
this.disposed = true;
this.disposedStackTrace = Environment.StackTrace;
}

base.Dispose(disposing);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
switch (metric.MetricType)
{
case MetricType.LongSum:
case MetricType.LongSumNonMonotonic:
{
var sum = new OtlpMetrics.Sum
{
IsMonotonic = true,
IsMonotonic = metric.MetricType == MetricType.LongSum,
AggregationTemporality = temporality,
};

Expand All @@ -169,10 +170,11 @@ internal static OtlpMetrics.Metric ToOtlpMetric(this Metric metric)
}

case MetricType.DoubleSum:
case MetricType.DoubleSumNonMonotonic:
{
var sum = new OtlpMetrics.Sum
{
IsMonotonic = true,
IsMonotonic = metric.MetricType == MetricType.DoubleSum,
AggregationTemporality = temporality,
};

Expand Down
25 changes: 6 additions & 19 deletions src/OpenTelemetry.Exporter.Prometheus.AspNetCore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,23 @@ dotnet add package --prerelease OpenTelemetry.Exporter.Prometheus.AspNetCore
### Step 3: Configure Prometheus Scraping Endpoint

* Register Prometheus scraping middleware using the
`UseOpenTelemetryPrometheusScrapingEndpoint` extension:
`UseOpenTelemetryPrometheusScrapingEndpoint` extension method
on `IApplicationBuilder` :

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseOpenTelemetryPrometheusScrapingEndpoint();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseOpenTelemetryPrometheusScrapingEndpoint();
```

Overloads of the `UseOpenTelemetryPrometheusScrapingEndpoint` extension are
provided to change the path or for more advanced configuration a predicate
function can be used:

```csharp
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseOpenTelemetryPrometheusScrapingEndpoint(
app.UseOpenTelemetryPrometheusScrapingEndpoint(
context => context.Request.Path == "/internal/metrics"
&& context.Connection.LocalPort == 5067);
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
```

## Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ namespace OpenTelemetry.Exporter.Prometheus
/// </summary>
internal static partial class PrometheusSerializer
{
/* Counter becomes counter
Gauge becomes gauge
Histogram becomes histogram
UpDownCounter becomes gauge
* https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/data-model.md#otlp-metric-points-to-prometheus
*/
private static readonly string[] MetricTypes = new string[]
{
"untyped", "counter", "gauge", "summary", "histogram", "histogram", "histogram", "histogram", "untyped",
"untyped", "counter", "gauge", "summary", "histogram", "histogram", "histogram", "histogram", "gauge",
};

public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
Expand Down
2 changes: 2 additions & 0 deletions src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceColl
static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
~static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder meterProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder!>! configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
OpenTelemetry.Metrics.MetricType.LongSumNonMonotonic = 138 -> OpenTelemetry.Metrics.MetricType
OpenTelemetry.Metrics.MetricType.DoubleSumNonMonotonic = 141 -> OpenTelemetry.Metrics.MetricType
2 changes: 2 additions & 0 deletions src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceColl
static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
~static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder meterProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder!>! configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
OpenTelemetry.Metrics.MetricType.LongSumNonMonotonic = 138 -> OpenTelemetry.Metrics.MetricType
OpenTelemetry.Metrics.MetricType.DoubleSumNonMonotonic = 141 -> OpenTelemetry.Metrics.MetricType
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceColl
static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
~static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder meterProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder!>! configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
OpenTelemetry.Metrics.MetricType.LongSumNonMonotonic = 138 -> OpenTelemetry.Metrics.MetricType
OpenTelemetry.Metrics.MetricType.DoubleSumNonMonotonic = 141 -> OpenTelemetry.Metrics.MetricType
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceColl
static Microsoft.Extensions.DependencyInjection.TracerProviderBuilderServiceCollectionExtensions.ConfigureOpenTelemetryTracing(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action<OpenTelemetry.Trace.TracerProviderBuilder!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
~static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Metrics.MeterProviderBuilder meterProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder> configure) -> OpenTelemetry.Metrics.MeterProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.ConfigureResource(this OpenTelemetry.Trace.TracerProviderBuilder! tracerProviderBuilder, System.Action<OpenTelemetry.Resources.ResourceBuilder!>! configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
OpenTelemetry.Metrics.MetricType.LongSumNonMonotonic = 138 -> OpenTelemetry.Metrics.MetricType
OpenTelemetry.Metrics.MetricType.DoubleSumNonMonotonic = 141 -> OpenTelemetry.Metrics.MetricType
3 changes: 3 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Allows samplers the ability to modify tracestate if desired.
([#3610](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3610))

* Added support for `UpDownCounter` and `ObservableUpDownCounter` instruments.
([#3606](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3606))

## 1.4.0-alpha.2

Released 2022-Aug-18
Expand Down
28 changes: 28 additions & 0 deletions src/OpenTelemetry/Metrics/Metric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ internal Metric(
aggType = AggregationType.DoubleSumIncomingCumulative;
this.MetricType = MetricType.DoubleSum;
}
else if (instrumentIdentity.InstrumentType == typeof(ObservableUpDownCounter<long>)
|| instrumentIdentity.InstrumentType == typeof(ObservableUpDownCounter<int>)
|| instrumentIdentity.InstrumentType == typeof(ObservableUpDownCounter<short>)
|| instrumentIdentity.InstrumentType == typeof(ObservableUpDownCounter<byte>))
{
aggType = AggregationType.LongSumIncomingCumulative;
this.MetricType = MetricType.LongSumNonMonotonic;
}
else if (instrumentIdentity.InstrumentType == typeof(UpDownCounter<long>)
|| instrumentIdentity.InstrumentType == typeof(UpDownCounter<int>)
|| instrumentIdentity.InstrumentType == typeof(UpDownCounter<short>)
|| instrumentIdentity.InstrumentType == typeof(UpDownCounter<byte>))
{
aggType = AggregationType.LongSumIncomingDelta;
this.MetricType = MetricType.LongSumNonMonotonic;
}
else if (instrumentIdentity.InstrumentType == typeof(UpDownCounter<double>)
|| instrumentIdentity.InstrumentType == typeof(UpDownCounter<float>))
{
aggType = AggregationType.DoubleSumIncomingDelta;
this.MetricType = MetricType.DoubleSumNonMonotonic;
}
else if (instrumentIdentity.InstrumentType == typeof(ObservableUpDownCounter<double>)
|| instrumentIdentity.InstrumentType == typeof(ObservableUpDownCounter<float>))
{
aggType = AggregationType.DoubleSumIncomingCumulative;
this.MetricType = MetricType.DoubleSumNonMonotonic;
}
else if (instrumentIdentity.InstrumentType == typeof(ObservableGauge<double>)
|| instrumentIdentity.InstrumentType == typeof(ObservableGauge<float>))
{
Expand Down
11 changes: 3 additions & 8 deletions src/OpenTelemetry/Metrics/MetricReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,11 @@ public abstract partial class MetricReader : IDisposable
var type when type == typeof(ObservableCounter<>) => AggregationTemporality.Delta,
var type when type == typeof(Histogram<>) => AggregationTemporality.Delta,

// Temporatlity is not defined for gauges, so this does not really affect anything.
// Temporality is not defined for gauges, so this does not really affect anything.
var type when type == typeof(ObservableGauge<>) => AggregationTemporality.Delta,

// With .NET 7 the OpenTelemetry .NET SDK will support UpDownCounters.
// These will be aggregated using Cumulative temporatlity.
// See:
// https://docs.microsoft.com/dotnet/api/system.diagnostics.metrics.updowncounter-1
// https://docs.microsoft.com/dotnet/api/system.diagnostics.metrics.observableupdowncounter-1
// var type when type == typeof(UpDownCounter<>) => AggregationTemporality.Cumulative,
// var type when type == typeof(ObservableUpDownCounter<>) => AggregationTemporality.Cumulative,
var type when type == typeof(UpDownCounter<>) => AggregationTemporality.Cumulative,
var type when type == typeof(ObservableUpDownCounter<>) => AggregationTemporality.Cumulative,

// TODO: Consider logging here because we should not fall through to this case.
_ => AggregationTemporality.Delta,
Expand Down
12 changes: 11 additions & 1 deletion src/OpenTelemetry/Metrics/MetricType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum MetricType : byte
0x50: HistogramWithMinMax (reserved)
0x60: ExponentialHistogram (reserved)
0x70: ExponentialHistogramWithMinMax (reserved)
0x80: Reserved
0x80: SumNonMonotonic
Point kind:
0x04: I1 (signed 1-byte integer)
Expand Down Expand Up @@ -69,5 +69,15 @@ public enum MetricType : byte
/// Histogram.
/// </summary>
Histogram = 0x40,

/// <summary>
/// Non-monotonic Sum of Long type.
/// </summary>
LongSumNonMonotonic = 0x8a,

/// <summary>
/// Non-monotonic Sum of Double type.
/// </summary>
DoubleSumNonMonotonic = 0x8d,
}
}
6 changes: 4 additions & 2 deletions src/OpenTelemetry/Metrics/MetricTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public static class MetricTypeExtensions

internal const MetricType METRIC_TYPE_MASK = (MetricType)0xf0;

internal const MetricType METRIC_TYPE_SUM = (MetricType)0x10;
internal const MetricType METRIC_TYPE_MONOTONIC_SUM = (MetricType)0x10;
internal const MetricType METRIC_TYPE_GAUGE = (MetricType)0x20;
/* internal const byte METRIC_TYPE_SUMMARY = 0x30; // not used */
internal const MetricType METRIC_TYPE_HISTOGRAM = (MetricType)0x40;
internal const MetricType METRIC_TYPE_NON_MONOTONIC_SUM = (MetricType)0x80;

internal const MetricType POINT_KIND_MASK = (MetricType)0x0f;

Expand All @@ -47,7 +48,8 @@ public static class MetricTypeExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsSum(this MetricType self)
{
return (self & METRIC_TYPE_MASK) == METRIC_TYPE_SUM;
var type = self & METRIC_TYPE_MASK;
return type == METRIC_TYPE_MONOTONIC_SUM || type == METRIC_TYPE_NON_MONOTONIC_SUM;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Loading

0 comments on commit 2bb1212

Please sign in to comment.