Skip to content

Commit

Permalink
Merge branch 'main' into reyang/clarify-versioning-story
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jun 7, 2023
2 parents 6d4e08f + 6e73bb9 commit cce9a7a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("OpenTelemetry" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Console" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Api.ProviderBuilderExtensions.Tests" + AssemblyInfo.PublicKey)]
1 change: 1 addition & 0 deletions src/OpenTelemetry.Api/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[assembly: InternalsVisibleTo("OpenTelemetry.Api.ProviderBuilderExtensions" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Api.ProviderBuilderExtensions.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Api.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Console" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.InMemory" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Extensions.Hosting.Tests" + AssemblyInfo.PublicKey)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
// </copyright>

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Exporter;
using OpenTelemetry.Internal;

Expand All @@ -26,6 +28,7 @@ public static class ConsoleExporterLoggingExtensions
/// </summary>
/// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
/// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
/// todo: [Obsolete("Call LoggerProviderBuilder.AddConsoleExporter instead this method will be removed in a future version.")]
public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions)
=> AddConsoleExporter(loggerOptions, configure: null);

Expand All @@ -35,6 +38,7 @@ public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLo
/// <param name="loggerOptions"><see cref="OpenTelemetryLoggerOptions"/> options to use.</param>
/// <param name="configure">Callback action for configuring <see cref="ConsoleExporterOptions"/>.</param>
/// <returns>The instance of <see cref="OpenTelemetryLoggerOptions"/> to chain the calls.</returns>
/// todo: [Obsolete("Call LoggerProviderBuilder.AddConsoleExporter instead this method will be removed in a future version.")]
public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLoggerOptions loggerOptions, Action<ConsoleExporterOptions> configure)
{
Guard.ThrowIfNull(loggerOptions);
Expand All @@ -43,5 +47,54 @@ public static OpenTelemetryLoggerOptions AddConsoleExporter(this OpenTelemetryLo
configure?.Invoke(options);
return loggerOptions.AddProcessor(new SimpleLogRecordExportProcessor(new ConsoleLogRecordExporter(options)));
}

/// <summary>
/// Adds Console exporter with LoggerProviderBuilder.
/// </summary>
/// <param name="loggerProviderBuilder"><see cref="LoggerProviderBuilder"/>.</param>
/// <returns>The supplied instance of <see cref="LoggerProviderBuilder"/> to chain the calls.</returns>
internal static LoggerProviderBuilder AddConsoleExporter(
this LoggerProviderBuilder loggerProviderBuilder)
=> AddConsoleExporter(loggerProviderBuilder, name: null, configure: null);

/// <summary>
/// Adds Console exporter with LoggerProviderBuilder.
/// </summary>
/// <param name="loggerProviderBuilder"><see cref="LoggerProviderBuilder"/>.</param>
/// <param name="configure">Callback action for configuring <see cref="ConsoleExporterOptions"/>.</param>
/// <returns>The supplied instance of <see cref="LoggerProviderBuilder"/> to chain the calls.</returns>
internal static LoggerProviderBuilder AddConsoleExporter(
this LoggerProviderBuilder loggerProviderBuilder,
Action<ConsoleExporterOptions> configure)
=> AddConsoleExporter(loggerProviderBuilder, name: null, configure);

/// <summary>
/// Adds Console exporter with LoggerProviderBuilder.
/// </summary>
/// <param name="loggerProviderBuilder"><see cref="LoggerProviderBuilder"/>.</param>
/// <param name="name">Name which is used when retrieving options.</param>
/// <param name="configure">Callback action for configuring <see cref="ConsoleExporterOptions"/>.</param>
/// <returns>The supplied instance of <see cref="LoggerProviderBuilder"/> to chain the calls.</returns>
internal static LoggerProviderBuilder AddConsoleExporter(
this LoggerProviderBuilder loggerProviderBuilder,
string name,
Action<ConsoleExporterOptions> configure)
{
Guard.ThrowIfNull(loggerProviderBuilder);

name ??= Options.DefaultName;

if (configure != null)
{
loggerProviderBuilder.ConfigureServices(services => services.Configure(name, configure));
}

return loggerProviderBuilder.AddProcessor(sp =>
{
var options = sp.GetRequiredService<IOptionsMonitor<ConsoleExporterOptions>>().Get(name);

return new SimpleLogRecordExportProcessor(new ConsoleLogRecordExporter(options));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\OpenTelemetrySdkEventSource.cs" Link="Includes\OpenTelemetrySdkEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\PeriodicExportingMetricReaderHelper.cs" Link="Includes\PeriodicExportingMetricReaderHelper.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\TagTransformer.cs" Link="Includes\TagTransformer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Metrics\Base2ExponentialBucketHistogram.LowerBoundary.cs" Link="Includes\Base2ExponentialBucketHistogram.LowerBoundary.cs" />
<!-- Note: OpenTelemetry.Exporter.Console temporarily sees OpenTelemetry.Api internals for LoggerProviderBuilder
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\SpanAttributeConstants.cs" Link="Includes\SpanAttributeConstants.cs" />
-->
<!-- Note: OpenTelemetry.Exporter.Console temporarily sees OpenTelemetry internals for LoggerProviderBuilder extensions
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\OpenTelemetrySdkEventSource.cs" Link="Includes\OpenTelemetrySdkEventSource.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\PeriodicExportingMetricReaderHelper.cs" Link="Includes\PeriodicExportingMetricReaderHelper.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\TagTransformer.cs" Link="Includes\TagTransformer.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\Shims\UnconditionalSuppressMessageAttribute.cs" Link="Includes\UnconditionalSuppressMessageAttribute.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Metrics\Base2ExponentialBucketHistogram.LowerBoundary.cs" Link="Includes\Base2ExponentialBucketHistogram.LowerBoundary.cs" />
-->
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,13 @@ public void OnStartActivity(Activity activity, object payload)
activity.SetTag(SemanticConventions.AttributeHttpUrl, GetUri(request));
activity.SetTag(SemanticConventions.AttributeHttpFlavor, HttpTagHelper.GetFlavorTagValueFromProtocol(request.Protocol));

var userAgent = request.Headers["User-Agent"].FirstOrDefault();
if (!string.IsNullOrEmpty(userAgent))
if (request.Headers.TryGetValue("User-Agent", out var values))
{
activity.SetTag(SemanticConventions.AttributeHttpUserAgent, userAgent);
var userAgent = values.Count > 0 ? values[0] : null;
if (!string.IsNullOrEmpty(userAgent))
{
activity.SetTag(SemanticConventions.AttributeHttpUserAgent, userAgent);
}
}

try
Expand Down
1 change: 1 addition & 0 deletions src/OpenTelemetry/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("OpenTelemetry.Tests" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Console" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.InMemory" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.AspNetCore" + AssemblyInfo.PublicKey)]
[assembly: InternalsVisibleTo("OpenTelemetry.Exporter.Prometheus.AspNetCore.Tests" + AssemblyInfo.PublicKey)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
using OpenTelemetry.Trace;

/*
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.23424.1000)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1702/22H2/2022Update/SunValley2)
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET SDK=7.0.203
[Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
| Method | EnableInstrumentation | Mean | Error | StdDev | Gen0 | Allocated |
|--------------------------- |---------------------- |---------:|--------:|--------:|-------:|----------:|
| GetRequestForAspNetCoreApp | None | 226.8 us | 4.00 us | 3.74 us | - | 2.45 KB |
| GetRequestForAspNetCoreApp | Traces | 235.2 us | 4.44 us | 4.15 us | 0.4883 | 3.59 KB |
| GetRequestForAspNetCoreApp | Metrics | 229.1 us | 4.44 us | 4.36 us | - | 2.92 KB |
| GetRequestForAspNetCoreApp | Traces, Metrics | 230.6 us | 4.54 us | 5.23 us | 0.4883 | 3.66 KB |
| GetRequestForAspNetCoreApp | None | 136.8 us | 1.56 us | 1.46 us | 0.4883 | 2.45 KB |
| GetRequestForAspNetCoreApp | Traces | 148.1 us | 0.88 us | 0.82 us | 0.7324 | 3.57 KB |
| GetRequestForAspNetCoreApp | Metrics | 144.4 us | 1.16 us | 1.08 us | 0.4883 | 2.92 KB |
| GetRequestForAspNetCoreApp | Traces, Metrics | 163.0 us | 1.60 us | 1.49 us | 0.7324 | 3.63 KB |
Allocation details for .NET 7:
Expand All @@ -45,7 +45,6 @@
* Casting of the struct `Microsoft.Extensions.Primitives.StringValues` to `IEnumerable<string>` by `HttpRequestHeaderValuesGetter`
- `TraceContextPropagator.Extract` = 24 B
- `BaggageContextPropagator.Extract` = 24 B
- `request.Headers["User-Agent"].FirstOrDefault()` = 24 B
* String creation for `HttpRequest.HostString.Host` = 40 B
* `Activity.TagsLinkedList` (this is allocated on the first Activity.SetTag call) = 40 B
* Boxing of `Port` number when adding it as a tag = 24 B
Expand All @@ -61,7 +60,7 @@
- System.Threading.ExecutionContext = 40 B
Baseline = 2.45 KB
With Traces = 2.45 + (1162 / 1024) = 2.45 + 1.14 = 3.59 KB
With Traces = 2.45 + (1138 / 1024) = 2.45 + 1.12 = 3.57 KB
// Metrics
Expand All @@ -76,7 +75,7 @@
Baseline = 2.45 KB
With Traces and Metrics = Baseline + With Traces + (With Metrics - (Activity creation + `Acitivity.Stop()`)) (they use the same activity)
= 2.45 + (1162 + 64) / 1024 = 2.45 + 1.2 = 3.55 KB (~3.56 KB)
= 2.45 + (1138 + 64) / 1024 = 2.45 + 1.17 = ~3.63KB
*/

namespace Benchmarks.Instrumentation
Expand Down

0 comments on commit cce9a7a

Please sign in to comment.