Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Ting committed Feb 8, 2023
2 parents d9be582 + 047cd05 commit 9cf9982
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 57 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ For significant contributions please make sure you have completed the following

* [ ] Appropriate `CHANGELOG.md` updated for non-trivial changes
* [ ] Design discussion issue #
* [ ] Changes in public API reviewed
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 1.4.0-rc.3

Released 2023-Feb-08

* Update OpenTelemetry to 1.4.0-rc.3
([#944](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/944))

Expand Down
30 changes: 18 additions & 12 deletions src/OpenTelemetry.Instrumentation.AWSLambda/AWSLambdaWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using OpenTelemetry.Instrumentation.AWSLambda.Implementation;
using OpenTelemetry.Internal;
using OpenTelemetry.Trace;

namespace OpenTelemetry.Instrumentation.AWSLambda;
Expand Down Expand Up @@ -69,6 +70,7 @@ public static TResult Trace<TInput, TResult>(
ILambdaContext context,
ActivityContext parentContext = default)
{
Guard.ThrowIfNull(lambdaHandler);
return TraceInternal(tracerProvider, lambdaHandler, input, context, parentContext);
}

Expand All @@ -93,12 +95,15 @@ public static void Trace<TInput>(
ILambdaContext context,
ActivityContext parentContext = default)
{
Func<TInput, ILambdaContext, object> func = (input, context) =>
Guard.ThrowIfNull(lambdaHandler);

object Handler(TInput input, ILambdaContext context)
{
lambdaHandler(input, context);
return null;
};
TraceInternal(tracerProvider, func, input, context, parentContext);
}

TraceInternal(tracerProvider, Handler, input, context, parentContext);
}

/// <summary>
Expand All @@ -123,12 +128,15 @@ public static Task TraceAsync<TInput>(
ILambdaContext context,
ActivityContext parentContext = default)
{
Func<TInput, ILambdaContext, Task<object>> func = async (input, context) =>
Guard.ThrowIfNull(lambdaHandler);

async Task<object> Handler(TInput input, ILambdaContext context)
{
await lambdaHandler(input, context);
await lambdaHandler(input, context).ConfigureAwait(false);
return null;
};
return TraceInternalAsync(tracerProvider, func, input, context, parentContext);
}

return TraceInternalAsync(tracerProvider, Handler, input, context, parentContext);
}

/// <summary>
Expand All @@ -154,6 +162,7 @@ public static Task<TResult> TraceAsync<TInput, TResult>(
ILambdaContext context,
ActivityContext parentContext = default)
{
Guard.ThrowIfNull(lambdaHandler);
return TraceInternalAsync(tracerProvider, lambdaHandler, input, context, parentContext);
}

Expand Down Expand Up @@ -182,10 +191,7 @@ internal static Activity OnFunctionStart<TInput>(TInput input, ILambdaContext co

private static void OnFunctionStop(Activity activity, TracerProvider tracerProvider)
{
if (activity != null)
{
activity.Stop();
}
activity?.Stop();

// force flush before function quit in case of Lambda freeze.
tracerProvider?.ForceFlush();
Expand Down Expand Up @@ -239,7 +245,7 @@ private static async Task<TResult> TraceInternalAsync<TInput, TResult>(
var activity = OnFunctionStart(input, context, parentContext);
try
{
var result = await handlerAsync(input, context);
var result = await handlerAsync(input, context).ConfigureAwait(false);
AWSLambdaHttpUtils.SetHttpTagsFromResult(activity, result);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal static string GetQueryString(APIGatewayProxyRequest request)
{
queryString.Append(separator)
.Append(HttpUtility.UrlEncode(parameterKvp.Key))
.Append("=")
.Append('=')
.Append(HttpUtility.UrlEncode(value));
separator = '&';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ElasticsearchClientInstrumentationOptions
/// <summary>
/// Gets or sets a value indicating whether the JSON request body should be parsed out of the request debug information and formatted as indented JSON.
/// </summary>
public bool ParseAndFormatRequest { get; set; } = false;
public bool ParseAndFormatRequest { get; set; }

/// <summary>
/// Gets or sets a value indicating whether or not the OpenTelemetry.Instrumentation.ElasticsearchClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public override void OnStartActivity(Activity activity, object payload)
SuppressInstrumentationScope.Enter();
}

var elasticIndex = this.GetElasticIndex(uri);
activity.DisplayName = this.GetDisplayName(activity, method, elasticIndex);
var elasticIndex = GetElasticIndex(uri);
activity.DisplayName = GetDisplayName(activity, method, elasticIndex);
activity.SetTag(SemanticConventions.AttributeDbSystem, DatabaseSystemName);

if (elasticIndex != null)
Expand Down Expand Up @@ -144,7 +144,7 @@ public override void OnStopActivity(Activity activity, object payload)
var debugInformation = this.debugInformationFetcher.Fetch(payload);
if (debugInformation != null && this.options.SetDbStatementForRequest)
{
var dbStatement = this.ParseAndFormatRequest(activity, debugInformation);
var dbStatement = this.ParseAndFormatRequest(debugInformation);
if (this.options.MaxDbStatementLength > 0 && dbStatement.Length > this.options.MaxDbStatementLength)
{
dbStatement = dbStatement.Substring(0, this.options.MaxDbStatementLength);
Expand Down Expand Up @@ -201,7 +201,7 @@ public override void OnStopActivity(Activity activity, object payload)
}
}

private string GetDisplayName(Activity activity, object method, string elasticType = null)
private static string GetDisplayName(Activity activity, object method, string elasticType = null)
{
switch (activity.OperationName)
{
Expand All @@ -223,7 +223,7 @@ private string GetDisplayName(Activity activity, object method, string elasticTy
}
}

private string GetElasticIndex(Uri uri)
private static string GetElasticIndex(Uri uri)
{
// first segment is always /
if (uri.Segments.Length < 2)
Expand All @@ -232,7 +232,7 @@ private string GetElasticIndex(Uri uri)
}

// operations starting with _ are not indices (_cat, _search, etc)
if (uri.Segments[1].StartsWith("_"))
if (uri.Segments[1].StartsWith("_", StringComparison.Ordinal))
{
return null;
}
Expand All @@ -245,15 +245,15 @@ private string GetElasticIndex(Uri uri)
return null;
}

if (elasticType.EndsWith("/"))
if (elasticType.EndsWith("/", StringComparison.Ordinal))
{
elasticType = elasticType.Substring(0, elasticType.Length - 1);
}

return elasticType;
}

private string ParseAndFormatRequest(Activity activity, string debugInformation)
private string ParseAndFormatRequest(string debugInformation)
{
if (!this.options.ParseAndFormatRequest)
{
Expand All @@ -275,9 +275,10 @@ private string ParseAndFormatRequest(Activity activity, string debugInformation)
return debugInformation;
}

using (doc)
using (var stream = new MemoryStream())
{
var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
using var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true });
doc.WriteTo(writer);
writer.Flush();
body = Encoding.UTF8.GetString(stream.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.RecordException.ge
OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Trace.TracerProviderBuilderExtensions
Owin.AppBuilderExtensions
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions> configureOwinInstrumentationOptions = null) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TracerProviderBuilderExtensions.AddOwinInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Owin.OwinInstrumentationOptions> configure) -> OpenTelemetry.Trace.TracerProviderBuilder
static Owin.AppBuilderExtensions.UseOpenTelemetry(this Owin.IAppBuilder appBuilder) -> Owin.IAppBuilder
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Instrumentation.Owin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Updated OpenTelemetry SDK to 1.3.2
([#917](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/917))
* Removes `AddOwinInstrumentation` method with default configure parameter.
([#929](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/929))

## 1.0.0-rc.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ public static class TracerProviderBuilderExtensions
/// Enables the incoming requests automatic data collection for OWIN.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configureOwinInstrumentationOptions">OWIN Request configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddOwinInstrumentation(this TracerProviderBuilder builder) =>
AddOwinInstrumentation(builder, configure: null);

/// <summary>
/// Enables the incoming requests automatic data collection for OWIN.
/// </summary>
/// <param name="builder"><see cref="TracerProviderBuilder"/> being configured.</param>
/// <param name="configure">OWIN Request configuration options.</param>
/// <returns>The instance of <see cref="TracerProviderBuilder"/> to chain the calls.</returns>
public static TracerProviderBuilder AddOwinInstrumentation(
this TracerProviderBuilder builder,
Action<OwinInstrumentationOptions> configureOwinInstrumentationOptions = null)
Action<OwinInstrumentationOptions> configure)
{
Guard.ThrowIfNull(builder);

var owinOptions = new OwinInstrumentationOptions();
configureOwinInstrumentationOptions?.Invoke(owinOptions);
configure?.Invoke(owinOptions);

OwinInstrumentationActivitySource.Options = owinOptions;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions
OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions.ProcessInstrumentationOptions() -> void
OpenTelemetry.Metrics.MeterProviderBuilderExtensions
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddProcessInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder) -> OpenTelemetry.Metrics.MeterProviderBuilder!
static OpenTelemetry.Metrics.MeterProviderBuilderExtensions.AddProcessInstrumentation(this OpenTelemetry.Metrics.MeterProviderBuilder! builder, System.Action<OpenTelemetry.Instrumentation.Process.ProcessInstrumentationOptions!>? configure) -> OpenTelemetry.Metrics.MeterProviderBuilder!
6 changes: 6 additions & 0 deletions src/OpenTelemetry.Instrumentation.Process/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* Removed CPU utilization metric `process.cpu.utilization`.
([#972](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/972))

* Removed `ProcessInstrumentationOptions` and
`AddProcessInstrumentation(this MeterProviderBuilder builder,`
`Action<ProcessInstrumentationOptions>? configure)`
from the public APIs.
([#973](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/973))

## 1.0.0-alpha.5

Released 2023-Feb-02
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// limitations under the License.
// </copyright>

using System;
using OpenTelemetry.Instrumentation.Process;
using OpenTelemetry.Internal;

Expand All @@ -26,29 +25,17 @@ namespace OpenTelemetry.Metrics;
public static class MeterProviderBuilderExtensions
{
/// <summary>
/// Enables runtime instrumentation.
/// Enables process instrumentation.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddProcessInstrumentation(this MeterProviderBuilder builder) => AddProcessInstrumentation(builder, configure: null);

/// <summary>
/// Enables runtime instrumentation.
/// </summary>
/// <param name="builder"><see cref="MeterProviderBuilder"/> being configured.</param>
/// <param name="configure">Runtime metrics options.</param>
/// <returns>The instance of <see cref="MeterProviderBuilder"/> to chain the calls.</returns>
public static MeterProviderBuilder AddProcessInstrumentation(
this MeterProviderBuilder builder,
Action<ProcessInstrumentationOptions>? configure)
this MeterProviderBuilder builder)
{
Guard.ThrowIfNull(builder);

var options = new ProcessInstrumentationOptions();
configure?.Invoke(options);

builder.AddMeter(ProcessMetrics.MeterName);

return builder.AddInstrumentation(() => new ProcessMetrics(options));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ namespace OpenTelemetry.Instrumentation.Process;
/// <summary>
/// Options to define the process metrics.
/// </summary>
public class ProcessInstrumentationOptions
internal class ProcessInstrumentationOptions
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ internal TelemetryClientMessageInspector(IDictionary<string, ActionMetadata> act
/// <inheritdoc/>
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
Guard.ThrowIfNull(request);
Guard.ThrowIfNull(channel);

try
{
if (WcfInstrumentationActivitySource.Options == null || WcfInstrumentationActivitySource.Options.OutgoingRequestFilter?.Invoke(request) == false)
{
WcfInstrumentationEventSource.Log.RequestIsFilteredOut();
return new State
{
SuppressionScope = this.SuppressDownstreamInstrumentation(),
SuppressionScope = SuppressDownstreamInstrumentation(),
};
}
}
Expand All @@ -60,14 +63,14 @@ public object BeforeSendRequest(ref Message request, IClientChannel channel)
WcfInstrumentationEventSource.Log.RequestFilterException(ex);
return new State
{
SuppressionScope = this.SuppressDownstreamInstrumentation(),
SuppressionScope = SuppressDownstreamInstrumentation(),
};
}

Activity activity = WcfInstrumentationActivitySource.ActivitySource.StartActivity(
WcfInstrumentationActivitySource.OutgoingRequestActivityName,
ActivityKind.Client);
IDisposable suppressionScope = this.SuppressDownstreamInstrumentation();
IDisposable suppressionScope = SuppressDownstreamInstrumentation();

if (activity != null)
{
Expand Down Expand Up @@ -143,6 +146,9 @@ public object BeforeSendRequest(ref Message request, IClientChannel channel)
/// <inheritdoc/>
public void AfterReceiveReply(ref Message reply, object correlationState)
{
Guard.ThrowIfNull(reply);
Guard.ThrowIfNull(correlationState);

State state = (State)correlationState;

state.SuppressionScope?.Dispose();
Expand Down Expand Up @@ -171,7 +177,7 @@ public void AfterReceiveReply(ref Message reply, object correlationState)
}
}

private IDisposable SuppressDownstreamInstrumentation()
private static IDisposable SuppressDownstreamInstrumentation()
{
return WcfInstrumentationActivitySource.Options?.SuppressDownstreamInstrumentation ?? false
? SuppressInstrumentationScope.Begin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Instrumentation.Wcf;
#if NETFRAMEWORK
Expand Down Expand Up @@ -45,13 +46,15 @@ public void AddBindingParameters(ContractDescription contractDescription, Servic
/// <inheritdoc />
public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
Guard.ThrowIfNull(clientRuntime);
TelemetryEndpointBehavior.ApplyClientBehaviorToClientRuntime(clientRuntime);
}

/// <inheritdoc />
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
{
#if NETFRAMEWORK
Guard.ThrowIfNull(dispatchRuntime);
TelemetryEndpointBehavior.ApplyDispatchBehaviorToEndpoint(dispatchRuntime.EndpointDispatcher);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ internal TelemetryDispatchMessageInspector(IDictionary<string, ActionMetadata> a
/// <inheritdoc/>
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
Guard.ThrowIfNull(request);
Guard.ThrowIfNull(channel);

try
{
if (WcfInstrumentationActivitySource.Options == null || WcfInstrumentationActivitySource.Options.IncomingRequestFilter?.Invoke(request) == false)
Expand Down
Loading

0 comments on commit 9cf9982

Please sign in to comment.