Skip to content

Commit

Permalink
OpenTelemetry now logs HTTP scheme and flavour for you
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanSaeed committed Aug 3, 2022
1 parent 4ca0be3 commit e66477c
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 138 deletions.
1 change: 0 additions & 1 deletion Source/ApiTemplate/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@
"condition": "(!OpenTelemetry)",
"exclude": [
"Source/ApiTemplate/Constants/OpenTelemetryAttributeName.cs",
"Source/ApiTemplate/Constants/OpenTelemetryHttpFlavour.cs",
"Source/ApiTemplate/TracerProviderBuilderExtensions.cs"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ public static class EndUser
/// </summary>
public static class Http
{
/// <summary>
/// The URI scheme identifying the used protocol.
/// </summary>
/// <example>E.g. http or https.</example>
public const string Scheme = "http.scheme";

/// <summary>
/// Kind of HTTP protocol used.
/// </summary>
/// <example>E.g. 1.0, 1.1, 2.0, SPDY or QUIC.</example>
public const string Flavor = "http.flavor";

/// <summary>
/// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ private static void Enrich(Activity activity, string eventName, object obj)
if (obj is HttpRequest request)
{
var context = request.HttpContext;
activity.AddTag(OpenTelemetryAttributeName.Http.Flavor, OpenTelemetryHttpFlavour.GetHttpFlavour(request.Protocol));
activity.AddTag(OpenTelemetryAttributeName.Http.Scheme, request.Scheme);
activity.AddTag(OpenTelemetryAttributeName.Http.ClientIP, context.Connection.RemoteIpAddress);
activity.AddTag(OpenTelemetryAttributeName.Http.RequestContentLength, request.ContentLength);
activity.AddTag(OpenTelemetryAttributeName.Http.RequestContentType, request.ContentType);
Expand Down
1 change: 0 additions & 1 deletion Source/GraphQLTemplate/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
"condition": "(!OpenTelemetry)",
"exclude": [
"Source/GraphQLTemplate/Constants/OpenTelemetryAttributeName.cs",
"Source/GraphQLTemplate/Constants/OpenTelemetryHttpFlavour.cs",
"Source/GraphQLTemplate/TracerProviderBuilderExtensions.cs"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ public static class EndUser
/// </summary>
public static class Http
{
/// <summary>
/// The URI scheme identifying the used protocol.
/// </summary>
/// <example>E.g. http or https.</example>
public const string Scheme = "http.scheme";

/// <summary>
/// Kind of HTTP protocol used.
/// </summary>
/// <example>E.g. 1.0, 1.1, 2.0, SPDY or QUIC.</example>
public const string Flavor = "http.flavor";

/// <summary>
/// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ private static void Enrich(Activity activity, string eventName, object obj)
if (obj is HttpRequest request)
{
var context = request.HttpContext;
activity.AddTag(OpenTelemetryAttributeName.Http.Flavor, OpenTelemetryHttpFlavour.GetHttpFlavour(request.Protocol));
activity.AddTag(OpenTelemetryAttributeName.Http.Scheme, request.Scheme);
activity.AddTag(OpenTelemetryAttributeName.Http.ClientIP, context.Connection.RemoteIpAddress);
activity.AddTag(OpenTelemetryAttributeName.Http.RequestContentLength, request.ContentLength);
activity.AddTag(OpenTelemetryAttributeName.Http.RequestContentType, request.ContentType);
Expand Down
1 change: 0 additions & 1 deletion Source/OrleansTemplate/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"condition": "(!OpenTelemetry)",
"exclude": [
"Source/OrleansTemplate.Abstractions/Constants/OpenTelemetryAttributeName.cs",
"Source/OrleansTemplate.Abstractions/Constants/OpenTelemetryHttpFlavour.cs",
"Source/OrleansTemplate.Server/TracerProviderBuilderExtensions.cs"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,6 @@ public static class EndUser
/// </summary>
public static class Http
{
/// <summary>
/// The URI scheme identifying the used protocol.
/// </summary>
/// <example>E.g. http or https.</example>
public const string Scheme = "http.scheme";

/// <summary>
/// Kind of HTTP protocol used.
/// </summary>
/// <example>E.g. 1.0, 1.1, 2.0, SPDY or QUIC.</example>
public const string Flavor = "http.flavor";

/// <summary>
/// The IP address of the original client behind all proxies, if known (e.g. from X-Forwarded-For).
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ private static void Enrich(Activity activity, string eventName, object obj)
if (obj is HttpRequest request)
{
var context = request.HttpContext;
activity.AddTag(OpenTelemetryAttributeName.Http.Flavor, GetHttpFlavour(request.Protocol));
activity.AddTag(OpenTelemetryAttributeName.Http.Scheme, request.Scheme);
activity.AddTag(OpenTelemetryAttributeName.Http.ClientIP, context.Connection.RemoteIpAddress);
activity.AddTag(OpenTelemetryAttributeName.Http.RequestContentLength, request.ContentLength);
activity.AddTag(OpenTelemetryAttributeName.Http.RequestContentType, request.ContentType);
Expand All @@ -82,26 +80,4 @@ private static void Enrich(Activity activity, string eventName, object obj)
activity.AddTag(OpenTelemetryAttributeName.Http.ResponseContentType, response.ContentType);
}
}

private static string GetHttpFlavour(string protocol)
{
if (HttpProtocol.IsHttp10(protocol))
{
return OpenTelemetryHttpFlavour.Http10;
}
else if (HttpProtocol.IsHttp11(protocol))
{
return OpenTelemetryHttpFlavour.Http11;
}
else if (HttpProtocol.IsHttp2(protocol))
{
return OpenTelemetryHttpFlavour.Http20;
}
else if (HttpProtocol.IsHttp3(protocol))
{
return OpenTelemetryHttpFlavour.Http30;
}

throw new InvalidOperationException($"Protocol {protocol} not recognised.");
}
}

0 comments on commit e66477c

Please sign in to comment.