Skip to content

Commit

Permalink
Merge branch 'main' into alanwest/revert-protobuf-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Apr 21, 2023
2 parents 9f03e70 + 678e9c4 commit 0720829
Show file tree
Hide file tree
Showing 27 changed files with 878 additions and 430 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Merging test results
run: reportgenerator -reports:TestResults/**/*.xml -targetdir:TestResults -reporttypes:Cobertura -assemblyFilters:"-microsoft.data.sqlclient*;-grpc.core*;-opentracing*"

- uses: codecov/[email protected].2
- uses: codecov/[email protected].3
with:
file: TestResults/Cobertura.xml
env_vars: OS
Expand Down
2 changes: 1 addition & 1 deletion build/Common.nonprod.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Please sort alphabetically.
Refer to https://docs.microsoft.com/nuget/concepts/package-versioning for semver syntax.
-->
<BenchmarkDotNetPkgVer>[0.13.3,0.14)</BenchmarkDotNetPkgVer>
<BenchmarkDotNetPkgVer>[0.13.5,0.14)</BenchmarkDotNetPkgVer>
<CommandLineParserPkgVer>[2.9.1,3.0)</CommandLineParserPkgVer>
<DotNetXUnitCliVer>[2.3.1,3.0)</DotNetXUnitCliVer>
<GoogleProtobufPkgVer>[3.19.4,4.0)</GoogleProtobufPkgVer>
Expand Down
10 changes: 2 additions & 8 deletions docs/logs/redaction/MyRedactionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ internal class MyRedactionProcessor : BaseProcessor<LogRecord>
{
public override void OnEnd(LogRecord logRecord)
{
if (logRecord.State == null)
if (logRecord.Attributes != null)
{
// When State is null, OTel SDK guarantees StateValues is populated
// TODO: Debug.Assert?
logRecord.StateValues = new MyClassWithRedactionEnumerator(logRecord.StateValues);
}
else if (logRecord.State is IReadOnlyList<KeyValuePair<string, object>> listOfKvp)
{
logRecord.State = new MyClassWithRedactionEnumerator(listOfKvp);
logRecord.Attributes = new MyClassWithRedactionEnumerator(logRecord.Attributes);
}
}
}
12 changes: 6 additions & 6 deletions docs/metrics/getting-started-aspnetcore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

var appBuilder = WebApplication.CreateBuilder(args);
var builder = WebApplication.CreateBuilder(args);

// Configure OpenTelemetry with metrics and auto-start.
appBuilder.Services.AddOpenTelemetry()
.ConfigureResource(builder => builder
.AddService(serviceName: "OTel.NET Getting Started"))
.WithMetrics(builder => builder
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource
.AddService(serviceName: builder.Environment.ApplicationName))
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddConsoleExporter((exporterOptions, metricReaderOptions) =>
{
metricReaderOptions.PeriodicExportingMetricReaderOptions.ExportIntervalMilliseconds = 1000;
}));

var app = appBuilder.Build();
var app = builder.Build();

app.MapGet("/", () => $"Hello from OpenTelemetry Metrics!");

Expand Down
5 changes: 5 additions & 0 deletions src/OpenTelemetry.Exporter.Console/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* Added direct reference to `System.Text.Encodings.Web` with minimum version of
`4.7.2` in response to [CVE-2021-26701](https://github.com/dotnet/runtime/issues/49377).

* Updated `LogRecord` console output: `Body` is now shown (if set),
`StateValues` are now written as `Attributes`, and `State` is no longer
processed.
([#4334](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4334))

## 1.5.0-alpha.2

Released 2023-Mar-31
Expand Down
38 changes: 9 additions & 29 deletions src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,42 +81,22 @@ public override ExportResult Export(in Batch<LogRecord> batch)
this.WriteLine($"{"LogRecord.FormattedMessage:",-RightPaddingLength}{logRecord.FormattedMessage}");
}

if (logRecord.State != null)
if (logRecord.Body != null)
{
if (logRecord.State is IReadOnlyList<KeyValuePair<string, object>> listKvp)
{
this.WriteLine("LogRecord.State (Key:Value):");
for (int i = 0; i < listKvp.Count; i++)
{
// Special casing {OriginalFormat}
// See https://github.com/open-telemetry/opentelemetry-dotnet/pull/3182
// for explanation.
var valueToTransform = listKvp[i].Key.Equals("{OriginalFormat}")
? new KeyValuePair<string, object>("OriginalFormat (a.k.a Body)", listKvp[i].Value)
: listKvp[i];

if (ConsoleTagTransformer.Instance.TryTransformTag(valueToTransform, out var result))
{
this.WriteLine($"{string.Empty,-4}{result}");
}
}
}
else
{
this.WriteLine($"{"LogRecord.State:",-RightPaddingLength}{logRecord.State}");
}
this.WriteLine($"{"LogRecord.Body:",-RightPaddingLength}{logRecord.Body}");
}
else if (logRecord.StateValues != null)

if (logRecord.Attributes != null)
{
this.WriteLine("LogRecord.StateValues (Key:Value):");
for (int i = 0; i < logRecord.StateValues.Count; i++)
this.WriteLine("LogRecord.Attributes (Key:Value):");
for (int i = 0; i < logRecord.Attributes.Count; i++)
{
// Special casing {OriginalFormat}
// See https://github.com/open-telemetry/opentelemetry-dotnet/pull/3182
// for explanation.
var valueToTransform = logRecord.StateValues[i].Key.Equals("{OriginalFormat}")
? new KeyValuePair<string, object>("OriginalFormat (a.k.a Body)", logRecord.StateValues[i].Value)
: logRecord.StateValues[i];
var valueToTransform = logRecord.Attributes[i].Key.Equals("{OriginalFormat}")
? new KeyValuePair<string, object>("OriginalFormat (a.k.a Body)", logRecord.Attributes[i].Value)
: logRecord.Attributes[i];

if (ConsoleTagTransformer.Instance.TryTransformTag(valueToTransform, out var result))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Unreleased

* The `OpenTelemetryLoggerOptions.AddOtlpExporter` extension no longer
automatically set `OpenTelemetryLoggerOptions.ParseStateValues` to `true`.
([#4334](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4334))

* Updated to use the new `LogRecord.Attributes` field as `StateValues` is now
marked obsolete.
([#4334](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4334))

## 1.5.0-alpha.2

Released 2023-Mar-31
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public static OpenTelemetryLoggerOptions AddOtlpExporter(this OpenTelemetryLogge
/// <summary>
/// Adds OTLP Exporter as a configuration to the OpenTelemetry ILoggingBuilder.
/// </summary>
/// <remarks>
/// Note: AddOtlpExporter automatically sets <see
/// cref="OpenTelemetryLoggerOptions.ParseStateValues"/> to <see
/// langword="true"/>.
/// </remarks>
/// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
/// <param name="configure">Callback action for configuring <see cref="OtlpExporterOptions"/>.</param>
/// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
Expand All @@ -53,8 +48,6 @@ private static OpenTelemetryLoggerOptions AddOtlpExporterInternal(
OpenTelemetryLoggerOptions loggerOptions,
Action<OtlpExporterOptions> configure)
{
loggerOptions.ParseStateValues = true;

var exporterOptions = new OtlpExporterOptions();

// TODO: We are using span/activity batch environment variable keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ internal static OtlpLogs.LogRecord ToOtlpLog(this LogRecord logRecord, SdkLimitO
bodyPopulatedFromFormattedMessage = true;
}

if (logRecord.StateValues != null)
if (logRecord.Attributes != null)
{
foreach (var stateValue in logRecord.StateValues)
foreach (var attribute in logRecord.Attributes)
{
// Special casing {OriginalFormat}
// See https://github.com/open-telemetry/opentelemetry-dotnet/pull/3182
// for explanation.
if (stateValue.Key.Equals("{OriginalFormat}") && !bodyPopulatedFromFormattedMessage)
if (attribute.Key.Equals("{OriginalFormat}") && !bodyPopulatedFromFormattedMessage)
{
otlpLogRecord.Body = new OtlpCommon.AnyValue { StringValue = stateValue.Value as string };
otlpLogRecord.Body = new OtlpCommon.AnyValue { StringValue = attribute.Value as string };
}
else if (OtlpKeyValueTransformer.Instance.TryTransformTag(stateValue, out var result, attributeValueLengthLimit))
else if (OtlpKeyValueTransformer.Instance.TryTransformTag(attribute, out var result, attributeValueLengthLimit))
{
otlpLogRecord.AddAttribute(result, attributeCountLimit);
}
Expand Down
7 changes: 7 additions & 0 deletions src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

* Added direct reference to `System.Text.Encodings.Web` with minimum version of
`4.7.2` due to [CVE-2021-26701](https://github.com/dotnet/runtime/issues/49377).
This impacts target frameworks `netstandard2.0` and `netstandard2.1` which has a
reference to `Microsoft.AspNetCore.Http.Abstractions` that depends on
`System.Text.Encodings.Web` >= 4.5.0.
([#4399](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4399))

* Improve perf by avoiding boxing of common status codes values.
([#4360](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4360),
[#4363](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4363))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWebPkgVer)" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="$(MicrosoftAspNetCoreHttpAbstractionsPkgVer)" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="$(MicrosoftAspNetCoreHttpFeaturesPkgVer)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWebPkgVer)" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="$(MicrosoftAspNetCoreHttpAbstractionsPkgVer)" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="$(MicrosoftAspNetCoreHttpFeaturesPkgVer)" />
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/OpenTelemetry/.publicApi/net462/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
OpenTelemetry.Logs.LogRecord.Attributes.get -> System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Logs.LogRecord.Attributes.set -> void
OpenTelemetry.Logs.LogRecord.Body.get -> string?
OpenTelemetry.Logs.LogRecord.Body.set -> void
OpenTelemetry.Metrics.AlwaysOffExemplarFilter
OpenTelemetry.Metrics.AlwaysOffExemplarFilter.AlwaysOffExemplarFilter() -> void
OpenTelemetry.Metrics.AlwaysOnExemplarFilter
Expand Down Expand Up @@ -43,4 +47,4 @@ OpenTelemetry.Metrics.MetricPoint.GetExponentialHistogramData() -> OpenTelemetry
~override OpenTelemetry.Metrics.AlwaysOnExemplarFilter.ShouldSample(long value, System.ReadOnlySpan<System.Collections.Generic.KeyValuePair<string, object>> tags) -> bool
~override OpenTelemetry.Metrics.TraceBasedExemplarFilter.ShouldSample(double value, System.ReadOnlySpan<System.Collections.Generic.KeyValuePair<string, object>> tags) -> bool
~override OpenTelemetry.Metrics.TraceBasedExemplarFilter.ShouldSample(long value, System.ReadOnlySpan<System.Collections.Generic.KeyValuePair<string, object>> tags) -> bool
OpenTelemetry.Resources.ResourceBuilder.AddDetector(System.Func<System.IServiceProvider!, OpenTelemetry.Resources.IResourceDetector!>! resourceDetectorFactory) -> OpenTelemetry.Resources.ResourceBuilder!
OpenTelemetry.Resources.ResourceBuilder.AddDetector(System.Func<System.IServiceProvider!, OpenTelemetry.Resources.IResourceDetector!>! resourceDetectorFactory) -> OpenTelemetry.Resources.ResourceBuilder!
4 changes: 4 additions & 0 deletions src/OpenTelemetry/.publicApi/net6.0/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
OpenTelemetry.Logs.LogRecord.Attributes.get -> System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Logs.LogRecord.Attributes.set -> void
OpenTelemetry.Logs.LogRecord.Body.get -> string?
OpenTelemetry.Logs.LogRecord.Body.set -> void
OpenTelemetry.Metrics.AlwaysOffExemplarFilter
OpenTelemetry.Metrics.AlwaysOffExemplarFilter.AlwaysOffExemplarFilter() -> void
OpenTelemetry.Metrics.AlwaysOnExemplarFilter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
OpenTelemetry.Logs.LogRecord.Attributes.get -> System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Logs.LogRecord.Attributes.set -> void
OpenTelemetry.Logs.LogRecord.Body.get -> string?
OpenTelemetry.Logs.LogRecord.Body.set -> void
OpenTelemetry.Metrics.AlwaysOffExemplarFilter
OpenTelemetry.Metrics.AlwaysOffExemplarFilter.AlwaysOffExemplarFilter() -> void
OpenTelemetry.Metrics.AlwaysOnExemplarFilter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
OpenTelemetry.Logs.LogRecord.Attributes.get -> System.Collections.Generic.IReadOnlyList<System.Collections.Generic.KeyValuePair<string!, object?>>?
OpenTelemetry.Logs.LogRecord.Attributes.set -> void
OpenTelemetry.Logs.LogRecord.Body.get -> string?
OpenTelemetry.Logs.LogRecord.Body.set -> void
OpenTelemetry.Metrics.AlwaysOffExemplarFilter
OpenTelemetry.Metrics.AlwaysOffExemplarFilter.AlwaysOffExemplarFilter() -> void
OpenTelemetry.Metrics.AlwaysOnExemplarFilter
Expand Down
7 changes: 7 additions & 0 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@
the `telemetry.sdk.*` attributes defined in the
[specification](https://github.com/open-telemetry/opentelemetry-specification/tree/12fcec1ff255b1535db75708e52a3a21f86f0fae/specification/resource/semantic_conventions#semantic-attributes-with-sdk-provided-default-value).
([#4369](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4369))

* Fixed an issue with `HashCode` computations throwing exceptions on .NET
Standard 2.1 targets.
([#4362](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4362))

* Update value of the resource attribute `telemetry.sdk.version` to show the tag
name which resembles the package version of the SDK.
([#4375](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4375))

* Tweaked the behavior of the `OpenTelemetryLoggerOptions.ParseStateValues`
flag, obsoleted `LogRecord.State` and `LogRecord.StateValues` properties, and
added `LogRecord.Body` and `LogRecord.Attributes` properties.
([#4334](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4334))

## 1.5.0-alpha.2

Released 2023-Mar-31
Expand Down
15 changes: 15 additions & 0 deletions src/OpenTelemetry/Internal/OpenTelemetrySdkEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ public void DroppedExportProcessorItems(string exportProcessorName, string expor
}
}

[NonEvent]
public void LoggerParseStateException<TState>(Exception exception)
{
if (this.IsEnabled(EventLevel.Warning, EventKeywords.All))
{
this.LoggerParseStateException(typeof(TState).FullName!, exception.ToInvariantString());
}
}

[Event(4, Message = "Unknown error in SpanProcessor event '{0}': '{1}'.", Level = EventLevel.Error)]
public void SpanProcessorException(string evnt, string ex)
{
Expand Down Expand Up @@ -284,6 +293,12 @@ public void InvalidEnvironmentVariable(string key, string? value)
this.WriteEvent(47, key, value);
}

[Event(48, Message = "Exception thrown parsing log state of type '{0}'. Exception: '{1}'", Level = EventLevel.Warning)]
public void LoggerParseStateException(string type, string error)
{
this.WriteEvent(48, type, error);
}

#if DEBUG
public class OpenTelemetryEventListener : EventListener
{
Expand Down
Loading

0 comments on commit 0720829

Please sign in to comment.