Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Nov 7, 2024
2 parents d05a377 + 4301c94 commit a1b0806
Show file tree
Hide file tree
Showing 113 changed files with 488 additions and 635 deletions.
2 changes: 1 addition & 1 deletion build/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<MicrosoftSourceLinkGitHubPkgVer>[8.0.0,9.0)</MicrosoftSourceLinkGitHubPkgVer>
<OpenTelemetryCoreUnstableLatestVersion>[1.9.0-beta.2]</OpenTelemetryCoreUnstableLatestVersion>
<OpenTelemetryCoreLatestVersion>[1.9.0,2.0)</OpenTelemetryCoreLatestVersion>
<OpenTelemetryCoreLatestPrereleaseVersion>[1.10.0-beta.1]</OpenTelemetryCoreLatestPrereleaseVersion>
<OpenTelemetryCoreLatestPrereleaseVersion>[1.10.0-rc.1]</OpenTelemetryCoreLatestPrereleaseVersion>
<StackExchangeRedisPkgVer>[2.6.122,3.0)</StackExchangeRedisPkgVer>
<ConfluentKafkaPkgVer>[2.4.0,3.0)</ConfluentKafkaPkgVer>
<CassandraCSharpDriverPkgVer>[3.16.0,4.0)</CassandraCSharpDriverPkgVer>
Expand Down
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
For configuration details see:
[OtlpProtobufEncoding](./README.md#otlpprotobufencoding).

* Update OpenTelemetry SDK version to `1.10.0-rc.1`.
([#2294](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2294))

## 1.9.0

Released 2024-Jun-21
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<OTelSdkVersion>$(OpenTelemetryCoreLatestVersion)</OTelSdkVersion>
<OTelSdkVersion>$(OpenTelemetryCoreLatestPrereleaseVersion)</OTelSdkVersion>
</PropertyGroup>

<PropertyGroup Condition="$(OTelSdkVersion.Contains('alpha')) OR $(OTelSdkVersion.Contains('beta')) OR $(OTelSdkVersion.Contains('rc'))">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Linq.Expressions;
using System.Reflection;

namespace OpenTelemetry.Exporter.Geneva;

// This export processor exports without synchronization.
// Once OpenTelemetry .NET officially support this,
// we can get rid of this class.
// This is currently only used in ETW export, where we know
// that the underlying system is safe under concurrent calls.
internal class ReentrantExportProcessor<T> : BaseExportProcessor<T>
where T : class
{
private static readonly Func<T, Batch<T>> CreateBatch = BuildCreateBatchDelegate();

public ReentrantExportProcessor(BaseExporter<T> exporter)
: base(exporter)
{
}

protected override void OnExport(T data)
{
this.exporter.Export(CreateBatch(data));
}

private static Func<T, Batch<T>> BuildCreateBatchDelegate()
{
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
var ctor = typeof(Batch<T>).GetConstructor(flags, null, new Type[] { typeof(T) }, null)
?? throw new InvalidOperationException("Batch ctor accepting a single item could not be found reflectively");
var value = Expression.Parameter(typeof(T), null);
var lambda = Expression.Lambda<Func<T, Batch<T>>>(Expression.New(ctor, value), value);
return lambda.Compile();
this.exporter.Export(new(data));
}
}
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OneCollector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
also be applied to subsequent `LogRecord`s in the same batch.
([#2205](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2205))

* Update OpenTelemetry SDK version to `1.10.0-rc.1` and removed the direct
reference to `Microsoft.Extensions.Configuration.Binder`.
([#2295](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2295))

## 1.9.3

Released 2024-Oct-11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
</PropertyGroup>

<PropertyGroup>
<OTelSdkVersion>$(OpenTelemetryCoreLatestVersion)</OTelSdkVersion>
<OTelSdkVersion>$(OpenTelemetryCoreLatestPrereleaseVersion)</OTelSdkVersion>
<DefineConstants Condition="$(OTelSdkVersion.Contains('alpha')) OR $(OTelSdkVersion.Contains('beta')) OR $(OTelSdkVersion.Contains('rc'))">$(DefineConstants);EXPOSE_EXPERIMENTAL_FEATURES</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTelemetry" Version="$(OTelSdkVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="$(MicrosoftExtensionsConfigurationBinderPkgVer)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public override void OnEventWritten(string name, object? payload)
case "CallElasticsearch.Stop":
this.OnStopActivity(activity, payload);
break;
default:
break;
}
}

Expand All @@ -69,12 +71,7 @@ private static string GetDisplayName(Activity activity, object? method, string?
case "CallElasticsearch" when method != null:
{
var methodName = MethodNameCache.GetOrAdd(method, $"Elasticsearch {method}");
if (elasticType == null)
{
return methodName;
}

return $"{methodName} {elasticType}";
return elasticType == null ? methodName : $"{methodName} {elasticType}";
}

default:
Expand Down Expand Up @@ -122,7 +119,7 @@ private string ParseAndFormatRequest(string debugInformation)
var request = ParseRequest.Match(debugInformation);
if (request.Success)
{
string? body = request.Groups[1]?.Value?.Trim();
var body = request.Groups[1]?.Value?.Trim();
if (body == null)
{
return debugInformation;
Expand Down Expand Up @@ -193,7 +190,7 @@ private void OnStartActivity(Activity activity, object? payload)
}

var uriHostNameType = Uri.CheckHostName(uri.Host);
if (uriHostNameType == UriHostNameType.IPv4 || uriHostNameType == UriHostNameType.IPv6)
if (uriHostNameType is UriHostNameType.IPv4 or UriHostNameType.IPv6)
{
activity.SetTag(SemanticConventions.AttributeNetPeerIp, uri.Host);
}
Expand Down Expand Up @@ -269,14 +266,10 @@ private void OnStopActivity(Activity activity, object? payload)

if (originalException is HttpRequestException)
{
if (originalException.InnerException is SocketException exception)
if (originalException.InnerException is SocketException { SocketErrorCode: SocketError.HostNotFound })
{
switch (exception.SocketErrorCode)
{
case SocketError.HostNotFound:
activity.SetStatus(Status.Error.WithDescription(originalException.Message));
return;
}
activity.SetStatus(Status.Error.WithDescription(originalException.Message));
return;
}

if (originalException.InnerException != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace OpenTelemetry.Instrumentation.EventCounters;
/// </summary>
public class EventCountersInstrumentationOptions
{
internal readonly HashSet<string> EventSourceNames = new();
internal readonly HashSet<string> EventSourceNames = [];

/// <summary>
/// Gets or sets the subscription interval in seconds for reading values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal sealed class EventCountersMetrics : EventListener
private const int MaxInstrumentNameLength = 63;

private readonly EventCountersInstrumentationOptions options;
private readonly List<EventSource> preInitEventSources = new();
private readonly List<EventSource> enabledEventSources = new();
private readonly List<EventSource> preInitEventSources = [];
private readonly List<EventSource> enabledEventSources = [];
private readonly ConcurrentDictionary<(string, string), Instrument> instruments = new();
private readonly ConcurrentDictionary<(string, string), double> values = new();
private bool isDisposed;
Expand All @@ -45,7 +45,7 @@ public EventCountersMetrics(EventCountersInstrumentationOptions options)
{
this.options = options;

foreach (EventSource eventSource in this.preInitEventSources)
foreach (var eventSource in this.preInitEventSources)
{
if (this.options.ShouldListenToSource(eventSource.Name))
{
Expand Down Expand Up @@ -167,7 +167,7 @@ private static Dictionary<string, string> GetEnableEventsArguments(EventCounters
/// </summary>
private static string GetInstrumentName(string sourceName, string eventName)
{
int totalLength = Prefix.Length + 1 + sourceName.Length + 1 + eventName.Length;
var totalLength = Prefix.Length + 1 + sourceName.Length + 1 + eventName.Length;
if (totalLength <= MaxInstrumentNameLength)
{
return string.Concat(Prefix, ".", sourceName, ".", eventName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static void InjectActivityProperties(IDictionary<string, string> jobPara

private static IEnumerable<string> ExtractActivityProperties(Dictionary<string, string> telemetryData, string key)
{
return telemetryData.TryGetValue(key, out var value) ? new[] { value } : Enumerable.Empty<string>();
return telemetryData.TryGetValue(key, out var value) ? [value] : [];
}

private void SetStatusAndRecordException(Activity activity, Exception exception)
Expand Down
27 changes: 11 additions & 16 deletions src/OpenTelemetry.Instrumentation.Http/HttpClientInstrumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace OpenTelemetry.Instrumentation.Http;
/// </summary>
internal sealed class HttpClientInstrumentation : IDisposable
{
private static readonly HashSet<string> ExcludedDiagnosticSourceEventsNet7OrGreater = new()
{
private static readonly HashSet<string> ExcludedDiagnosticSourceEventsNet7OrGreater =
[
"System.Net.Http.Request",
"System.Net.Http.Response",
"System.Net.Http.HttpRequestOut",
};
"System.Net.Http.HttpRequestOut"
];

private static readonly HashSet<string> ExcludedDiagnosticSourceEvents = new()
{
private static readonly HashSet<string> ExcludedDiagnosticSourceEvents =
[
"System.Net.Http.Request",
"System.Net.Http.Response",
};
"System.Net.Http.Response"
];

private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

Expand All @@ -43,14 +43,9 @@ public HttpClientInstrumentation(HttpClientTraceInstrumentationOptions options)
// the framework will fall back to creating activity anyways due to active diagnostic source listener
// To prevent this, isEnabled is implemented which will return false always
// so that the sampler's decision is respected.
if (HttpHandlerDiagnosticListener.IsNet7OrGreater)
{
this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabledNet7OrGreater, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent);
}
else
{
this.diagnosticSourceSubscriber = new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabled, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent);
}
this.diagnosticSourceSubscriber = HttpHandlerDiagnosticListener.IsNet7OrGreater
? new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabledNet7OrGreater, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent)
: new DiagnosticSourceSubscriber(new HttpHandlerDiagnosticListener(options), this.isEnabled, HttpInstrumentationEventSource.Log.UnknownErrorProcessingEvent);

this.diagnosticSourceSubscriber.Subscribe();
}
Expand Down
8 changes: 4 additions & 4 deletions src/OpenTelemetry.Instrumentation.Http/HttpClientMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace OpenTelemetry.Instrumentation.Http;
/// </summary>
internal sealed class HttpClientMetrics : IDisposable
{
private static readonly HashSet<string> ExcludedDiagnosticSourceEvents = new()
{
private static readonly HashSet<string> ExcludedDiagnosticSourceEvents =
[
"System.Net.Http.Request",
"System.Net.Http.Response",
};
"System.Net.Http.Response"
];

private readonly DiagnosticSourceSubscriber diagnosticSourceSubscriber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ internal bool EventFilterHttpRequestMessage(string activityName, object arg1)
{
return
this.FilterHttpRequestMessage == null ||
!TryParseHttpRequestMessage(activityName, arg1, out HttpRequestMessage? requestMessage) ||
!TryParseHttpRequestMessage(activityName, arg1, out var requestMessage) ||
this.FilterHttpRequestMessage(requestMessage);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public override void OnEventWritten(string name, object? payload)
this.OnException(activity, payload);
}

break;
default:
break;
}
}
Expand All @@ -81,7 +83,7 @@ public void OnStartActivity(Activity activity, object? payload)
// By this time, samplers have already run and
// activity.IsAllDataRequested populated accordingly.

if (!TryFetchRequest(payload, out HttpRequestMessage? request))
if (!TryFetchRequest(payload, out var request))
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnStartActivity));
return;
Expand Down Expand Up @@ -109,7 +111,7 @@ public void OnStartActivity(Activity activity, object? payload)
{
try
{
if (this.options.EventFilterHttpRequestMessage(activity.OperationName, request) == false)
if (!this.options.EventFilterHttpRequestMessage(activity.OperationName, request))
{
HttpInstrumentationEventSource.Log.RequestIsFilteredOut(activity.OperationName);
activity.IsAllDataRequested = false;
Expand Down Expand Up @@ -161,12 +163,7 @@ public void OnStartActivity(Activity activity, object? payload)
#endif
static bool TryFetchRequest(object? payload, [NotNullWhen(true)] out HttpRequestMessage? request)
{
if (!StartRequestFetcher.TryFetch(payload, out request) || request == null)
{
return false;
}

return true;
return StartRequestFetcher.TryFetch(payload, out request) && request != null;
}
}

Expand All @@ -176,7 +173,7 @@ public void OnStopActivity(Activity activity, object? payload)
{
var requestTaskStatus = GetRequestStatus(payload);

ActivityStatusCode currentStatusCode = activity.Status;
var currentStatusCode = activity.Status;
if (requestTaskStatus != TaskStatus.RanToCompletion)
{
if (requestTaskStatus == TaskStatus.Canceled)
Expand All @@ -200,7 +197,7 @@ public void OnStopActivity(Activity activity, object? payload)
}
}

if (TryFetchResponse(payload, out HttpResponseMessage? response))
if (TryFetchResponse(payload, out var response))
{
if (currentStatusCode == ActivityStatusCode.Unset)
{
Expand Down Expand Up @@ -246,20 +243,15 @@ static TaskStatus GetRequestStatus(object? payload)
#endif
static bool TryFetchResponse(object? payload, [NotNullWhen(true)] out HttpResponseMessage? response)
{
if (StopResponseFetcher.TryFetch(payload, out response) && response != null)
{
return true;
}

return false;
return StopResponseFetcher.TryFetch(payload, out response) && response != null;
}
}

public void OnException(Activity activity, object? payload)
{
if (activity.IsAllDataRequested)
{
if (!TryFetchException(payload, out Exception? exc))
if (!TryFetchException(payload, out var exc))
{
HttpInstrumentationEventSource.Log.NullPayload(nameof(HttpHandlerDiagnosticListener), nameof(this.OnException));
return;
Expand Down Expand Up @@ -299,12 +291,7 @@ public void OnException(Activity activity, object? payload)
#endif
static bool TryFetchException(object? payload, [NotNullWhen(true)] out Exception? exc)
{
if (!StopExceptionFetcher.TryFetch(payload, out exc) || exc == null)
{
return false;
}

return true;
return StopExceptionFetcher.TryFetch(payload, out exc) && exc != null;
}
}

Expand Down
Loading

0 comments on commit a1b0806

Please sign in to comment.