Skip to content

Commit

Permalink
Merge branch 'main' into nullable-aws-sampler-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek authored Aug 31, 2023
2 parents 0ec567f + 10ffaad commit 84a68a1
Show file tree
Hide file tree
Showing 38 changed files with 756 additions and 129 deletions.
5 changes: 5 additions & 0 deletions examples/wcf/client-netframework/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<behavior name="telemetry">
<telemetryExtension />
</behavior>
<behavior name="webHttp">
<telemetryExtension />
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
Expand All @@ -28,6 +32,7 @@
<client>
<endpoint address="http://localhost:9009/Telemetry" binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_Http" />
<endpoint address="net.tcp://localhost:9090/Telemetry" binding="netTcpBinding" bindingConfiguration="netTCPConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_Tcp" />
<endpoint address="http://localhost:9009/Telemetry/rest" binding="webHttpBinding" behaviorConfiguration="webHttp" contract="Examples.Wcf.IStatusServiceContract" name="StatusService_Rest" />
</client>
</system.serviceModel>
</configuration>
1 change: 1 addition & 0 deletions examples/wcf/client-netframework/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static async Task Main()

await CallService("StatusService_Http").ConfigureAwait(false);
await CallService("StatusService_Tcp").ConfigureAwait(false);
await CallService("StatusService_Rest").ConfigureAwait(false);

Console.WriteLine("Press enter to exit.");
Console.ReadLine();
Expand Down
9 changes: 7 additions & 2 deletions examples/wcf/server-netframework/App.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<extensions>
Expand All @@ -11,6 +11,10 @@
<behavior name="telemetry">
<telemetryExtension />
</behavior>
<behavior name="webHttp">
<telemetryExtension />
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
Expand All @@ -27,8 +31,9 @@
</bindings>
<services>
<service name="Examples.Wcf.Server.StatusService">
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" />
<endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpConfig" behaviorConfiguration="telemetry" address="" contract="Examples.Wcf.IStatusServiceContract" />
<endpoint binding="netTcpBinding" bindingConfiguration="netTCPConfig" behaviorConfiguration="telemetry" contract="Examples.Wcf.IStatusServiceContract" />
<endpoint binding="webHttpBinding" behaviorConfiguration="webHttp" address="rest" contract="Examples.Wcf.IStatusServiceContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9009/Telemetry" />
Expand Down
3 changes: 2 additions & 1 deletion examples/wcf/shared/Examples.Wcf.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. -->
Expand All @@ -7,6 +7,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
6 changes: 6 additions & 0 deletions examples/wcf/shared/IStatusServiceContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
// </copyright>

using System.ServiceModel;
#if NETFRAMEWORK
using System.ServiceModel.Web;
#endif
using System.Threading.Tasks;

namespace Examples.Wcf;

[ServiceContract(Namespace = "http://opentelemetry.io/", Name = "StatusService", SessionMode = SessionMode.Allowed)]
public interface IStatusServiceContract
{
#if NETFRAMEWORK
[WebInvoke]
#endif
[OperationContract]
Task<StatusResponse> PingAsync(StatusRequest request);
}
4 changes: 2 additions & 2 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\package-Extensions.AWSXRay.yml = .github\workflows\package-Extensions.AWSXRay.yml
.github\workflows\package-Extensions.AzureMonitor.yml = .github\workflows\package-Extensions.AzureMonitor.yml
.github\workflows\package-Extensions.Docker.yml = .github\workflows\package-Extensions.Docker.yml
.github\workflows\package-Extensions.PersistentStorage.Abstractions.yml = .github\workflows\package-Extensions.PersistentStorage.Abstractions.yml
.github\workflows\package-Extensions.PersistentStorage.yml = .github\workflows\package-Extensions.PersistentStorage.yml
.github\workflows\package-Extensions.yml = .github\workflows\package-Extensions.yml
.github\workflows\package-Instrumentation.AspNet.TelemetryHttpModule.yml = .github\workflows\package-Instrumentation.AspNet.TelemetryHttpModule.yml
.github\workflows\package-Instrumentation.AspNet.yml = .github\workflows\package-Instrumentation.AspNet.yml
Expand All @@ -61,6 +59,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\package-Instrumentation.Runtime.yml = .github\workflows\package-Instrumentation.Runtime.yml
.github\workflows\package-Instrumentation.StackExchangeRedis.yml = .github\workflows\package-Instrumentation.StackExchangeRedis.yml
.github\workflows\package-Instrumentation.Wcf.yml = .github\workflows\package-Instrumentation.Wcf.yml
.github\workflows\package-PersistentStorage.Abstractions.yml = .github\workflows\package-PersistentStorage.Abstractions.yml
.github\workflows\package-PersistentStorage.FileSystem.yml = .github\workflows\package-PersistentStorage.FileSystem.yml
.github\workflows\sanitycheck.yml = .github\workflows\sanitycheck.yml
.github\workflows\stale.yml = .github\workflows\stale.yml
EndProjectSection
Expand Down
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.6.0-rc.1

Released 2023-Aug-28

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const OpenTelemetry.Instrumentation.Quartz.OperationName.Job.Execute = "Quartz.Job.Execute" -> string
const OpenTelemetry.Instrumentation.Quartz.OperationName.Job.Veto = "Quartz.Job.Veto" -> string
const OpenTelemetry.Instrumentation.Quartz.OperationName.Job.Execute = "Quartz.Job.Execute" -> string!
const OpenTelemetry.Instrumentation.Quartz.OperationName.Job.Veto = "Quartz.Job.Veto" -> string!
OpenTelemetry.Instrumentation.Quartz.OperationName
OpenTelemetry.Instrumentation.Quartz.OperationName.Job
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity, string, object>
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.Enrich.get -> System.Action<System.Diagnostics.Activity!, string!, object!>?
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.Enrich.set -> void
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.QuartzInstrumentationOptions() -> void
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.RecordException.get -> bool
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.RecordException.set -> void
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.TracedOperations.get -> System.Collections.Generic.HashSet<string>
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.TracedOperations.get -> System.Collections.Generic.HashSet<string!>!
OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions.TracedOperations.set -> void
OpenTelemetry.Trace.TraceProviderBuilderExtensions
static OpenTelemetry.Trace.TraceProviderBuilderExtensions.AddQuartzInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TraceProviderBuilderExtensions.AddQuartzInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder builder, System.Action<OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions> configure) -> OpenTelemetry.Trace.TracerProviderBuilder
static OpenTelemetry.Trace.TraceProviderBuilderExtensions.AddQuartzInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder) -> OpenTelemetry.Trace.TracerProviderBuilder!
static OpenTelemetry.Trace.TraceProviderBuilderExtensions.AddQuartzInstrumentation(this OpenTelemetry.Trace.TracerProviderBuilder! builder, System.Action<OpenTelemetry.Instrumentation.Quartz.QuartzInstrumentationOptions!>? configure) -> OpenTelemetry.Trace.TracerProviderBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public override void OnStartActivity(Activity activity, object payload)
try
{
this.JobDetailsPropertyFetcher.TryFetch(payload, out var jobDetails);
this.options.Enrich?.Invoke(activity, "OnStartActivity", jobDetails);
if (jobDetails != null)
{
this.options.Enrich?.Invoke(activity, "OnStartActivity", jobDetails);
}
}
catch (Exception ex)
{
Expand All @@ -77,7 +80,10 @@ public override void OnStopActivity(Activity activity, object payload)
try
{
this.JobDetailsPropertyFetcher.TryFetch(payload, out var jobDetails);
this.options.Enrich?.Invoke(activity, "OnStopActivity", jobDetails);
if (jobDetails != null)
{
this.options.Enrich?.Invoke(activity, "OnStopActivity", jobDetails);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -135,7 +141,7 @@ private static ActivityKind GetActivityKind(Activity activity)
};
}

private static string GetTag(IEnumerable<KeyValuePair<string, string>> tags, string tagName)
private static string? GetTag(IEnumerable<KeyValuePair<string, string?>> tags, string tagName)
{
var tag = tags.SingleOrDefault(kv => kv.Key == tagName);
return tag.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<IncludeSharedInstrumentationSource>true</IncludeSharedInstrumentationSource>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<IncludeSharedExceptionExtensionsSource>true</IncludeSharedExceptionExtensionsSource>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OpenTelemetry.Api" Version="$(OpenTelemetryCoreLatestVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class QuartzInstrumentationOptions
/// <para>object: the raw object from which additional information can be extracted to enrich the activity.
/// The type of this object depends on the event, which is given by the above parameter.</para>
/// </remarks>
public Action<Activity, string, object> Enrich { get; set; }
public Action<Activity, string, object>? Enrich { get; set; }

/// <summary>
/// Gets or sets a value indicating whether the exception will be recorded as ActivityEvent or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static TracerProviderBuilder AddQuartzInstrumentation(
/// <returns>The instance of <see cref="TraceProviderBuilderExtensions"/> to chain the calls.</returns>
public static TracerProviderBuilder AddQuartzInstrumentation(
this TracerProviderBuilder builder,
Action<QuartzInstrumentationOptions> configure)
Action<QuartzInstrumentationOptions>? configure)
{
Guard.ThrowIfNull(builder);

Expand Down
7 changes: 7 additions & 0 deletions src/OpenTelemetry.Instrumentation.Wcf/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Unreleased

## 1.0.0-rc.12

Released 2023-Aug-30

* Added support for non-SOAP requests.
([#1251](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1251))

## 1.0.0-rc.11

Released 2023-Aug-14
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// <copyright file="HttpRequestMessagePropertyWrapper.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;
using System.Diagnostics;
using System.Net;
using System.Reflection;

namespace OpenTelemetry.Instrumentation.Wcf.Implementation;

/// <summary>
/// This is a reflection-based wrapper around the HttpRequestMessageProperty class. It is done this way so we don't need to
/// have an explicit reference to System.ServiceModel.Http.dll. If the consuming application has a reference to
/// System.ServiceModel.Http.dll then the HttpRequestMessageProperty class will be available (IsHttpFunctionalityEnabled == true).
/// If the consuming application does not have a reference to System.ServiceModel.Http.dll then all http-related functionality
/// will be disabled (IsHttpFunctionalityEnabled == false).
/// </summary>
internal static class HttpRequestMessagePropertyWrapper
{
private static readonly ReflectedInfo ReflectedValues = Initialize();

public static bool IsHttpFunctionalityEnabled => ReflectedValues != null;

public static string Name
{
get
{
AssertHttpEnabled();
return ReflectedValues.Name;
}
}

public static object CreateNew()
{
AssertHttpEnabled();
return Activator.CreateInstance(ReflectedValues.Type);
}

public static WebHeaderCollection GetHeaders(object httpRequestMessageProperty)
{
AssertHttpEnabled();
AssertIsFrameworkMessageProperty(httpRequestMessageProperty);
return ReflectedValues.HeadersFetcher.Fetch(httpRequestMessageProperty);
}

private static ReflectedInfo Initialize()
{
Type type = null;
try
{
type = Type.GetType(
"System.ServiceModel.Channels.HttpRequestMessageProperty, System.ServiceModel, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
true);

var headersProp = type.GetProperty("Headers", BindingFlags.Public | BindingFlags.Instance, null, typeof(WebHeaderCollection), Array.Empty<Type>(), null);
if (headersProp == null)
{
throw new NotSupportedException("HttpRequestMessageProperty.Headers property not found");
}

var nameProp = type.GetProperty("Name", BindingFlags.Public | BindingFlags.Static, null, typeof(string), Array.Empty<Type>(), null);
if (nameProp == null)
{
throw new NotSupportedException("HttpRequestMessageProperty.Name property not found");
}

return new ReflectedInfo
{
Type = type,
Name = (string)nameProp.GetValue(null),
HeadersFetcher = new PropertyFetcher<WebHeaderCollection>("Headers"),
};
}
catch (Exception ex)
{
WcfInstrumentationEventSource.Log.HttpServiceModelReflectionFailedToBind(ex, type?.Assembly);
}

return null;
}

[Conditional("DEBUG")]
private static void AssertHttpEnabled()
{
if (!IsHttpFunctionalityEnabled)
{
throw new InvalidOperationException("Http functionality is not enabled, check IsHttpFunctionalityEnabled before calling this method");
}
}

[Conditional("DEBUG")]
private static void AssertIsFrameworkMessageProperty(object httpRequestMessageProperty)
{
AssertHttpEnabled();
if (httpRequestMessageProperty == null || !httpRequestMessageProperty.GetType().Equals(ReflectedValues.Type))
{
throw new ArgumentException("Object must be of type HttpRequestMessageProperty");
}
}

private sealed class ReflectedInfo
{
public Type Type;
public string Name;
public PropertyFetcher<WebHeaderCollection> HeadersFetcher;
}
}
Loading

0 comments on commit 84a68a1

Please sign in to comment.