Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit 6c40569

Browse files
http out - update to the latest spec (#73)
1 parent f6a31ca commit 6c40569

File tree

5 files changed

+63
-96
lines changed

5 files changed

+63
-96
lines changed

src/OpenCensus.Abstractions/Trace/SpanAttributeConstants.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@ internal static class SpanAttributeConstants
2323
public const string HttpUserAgentKey = "http.user_agent";
2424
public const string HttpPathKey = "http.path";
2525
public const string HttpHostKey = "http.host";
26+
public const string HttpUrlKey = "http.url";
2627
public const string HttpRequestSizeKey = "http.request.size";
2728
public const string HttpResponseSizeKey = "http.response.size";
2829
public const string HttpRouteKey = "http.route";
29-
30-
public const string MvcControllerMethod = "mvc.controller.method";
31-
public const string MvcControllerClass = "mvc.controller.class";
32-
33-
public const string MvcViewFilePath = "mvc.view.FilePath";
34-
35-
public const string ErrorKey = "error";
36-
public const string ErrorStackTrace = "error.stack.trace";
3730
}
3831
}

src/OpenCensus.Abstractions/Trace/SpanExtensions.cs

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ public static ISpan PutHttpHostAttribute(this ISpan span, string hostName, int p
108108
return span;
109109
}
110110

111+
/// <summary>
112+
/// Helper method that populates span properties from host and port
113+
/// to https://github.com/census-instrumentation/opencensus-specs/blob/4954074adf815f437534457331178194f6847ff9/trace/HTTP.md.
114+
/// </summary>
115+
/// <param name="span">Span to fill out.</param>
116+
/// <param name="rawUrl">Raw url.</param>
117+
/// <returns>Span with populated url properties.</returns>
118+
public static ISpan PutHttpRawUrlAttribute(this ISpan span, string rawUrl)
119+
{
120+
if (!string.IsNullOrEmpty(rawUrl))
121+
{
122+
span.PutAttribute(SpanAttributeConstants.HttpUrlKey, AttributeValue.StringAttributeValue(rawUrl));
123+
}
124+
125+
return span;
126+
}
127+
111128
/// <summary>
112129
/// Helper method that populates span properties from url path according
113130
/// to https://github.com/census-instrumentation/opencensus-specs/blob/4954074adf815f437534457331178194f6847ff9/trace/HTTP.md.
@@ -147,67 +164,6 @@ public static ISpan PutHttpRequestSizeAttribute(this ISpan span, long size)
147164
return span;
148165
}
149166

150-
/// <summary>
151-
/// Helper method that populates span properties from error attribute
152-
/// according to https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table.
153-
/// </summary>
154-
/// <param name="span">Span to fill out.</param>
155-
/// <param name="error">Indicate whether span ended with error.</param>
156-
/// <returns>Span with populated properties.</returns>
157-
public static ISpan PutErrorAttribute(this ISpan span, bool error = true)
158-
{
159-
span.PutAttribute(SpanAttributeConstants.ErrorKey, AttributeValue.BooleanAttributeValue(error));
160-
return span;
161-
}
162-
163-
/// <summary>
164-
/// Stores error stack trace into the span as an attribute.
165-
/// </summary>
166-
/// <param name="span">Span to store attribute on.</param>
167-
/// <param name="errorStackTrace">Error stack trace to store.</param>
168-
/// <returns>Span with the populated error stack trace attribute.</returns>
169-
public static ISpan PutErrorStackTraceAttribute(this ISpan span, string errorStackTrace)
170-
{
171-
span.PutAttribute(SpanAttributeConstants.ErrorStackTrace, AttributeValue.StringAttributeValue(errorStackTrace));
172-
return span;
173-
}
174-
175-
/// <summary>
176-
/// Populates MVC controller class attribute.
177-
/// </summary>
178-
/// <param name="span">Span to store attribute on.</param>
179-
/// <param name="className">MVC controller class name.</param>
180-
/// <returns>Span with the populated MVC controller class attribute.</returns>
181-
public static ISpan PutMvcControllerClass(this ISpan span, string className)
182-
{
183-
span.PutAttribute(SpanAttributeConstants.MvcControllerClass, AttributeValue.StringAttributeValue(className));
184-
return span;
185-
}
186-
187-
/// <summary>
188-
/// Populates MVC controller action attribute.
189-
/// </summary>
190-
/// <param name="span">Span to store attribute on.</param>
191-
/// <param name="actionName">MVC controller action name.</param>
192-
/// <returns>Span with the populated MVC controller action attribute.</returns>
193-
public static ISpan PutMvcControllerAction(this ISpan span, string actionName)
194-
{
195-
span.PutAttribute(SpanAttributeConstants.MvcControllerMethod, AttributeValue.StringAttributeValue(actionName));
196-
return span;
197-
}
198-
199-
/// <summary>
200-
/// Populates MVC view attribute on the span.
201-
/// </summary>
202-
/// <param name="span">Span to store attribute on.</param>
203-
/// <param name="viewExecutingFilePath">View executing file path.</param>
204-
/// <returns>Span with the populated view executing file path.</returns>
205-
public static ISpan PutMvcViewExecutingFilePath(this ISpan span, string viewExecutingFilePath)
206-
{
207-
span.PutAttribute(SpanAttributeConstants.MvcViewFilePath, AttributeValue.StringAttributeValue(viewExecutingFilePath));
208-
return span;
209-
}
210-
211167
/// <summary>
212168
/// Helper method that populates span properties from http status code according
213169
/// to https://github.com/census-instrumentation/opencensus-specs/blob/4954074adf815f437534457331178194f6847ff9/trace/HTTP.md.

src/OpenCensus.Collector.Dependencies/Implementation/HttpHandlerDiagnosticListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public override void OnStartActivity(Activity activity, object payload)
6464
span.PutHttpPathAttribute(request.RequestUri.AbsolutePath);
6565
request.Headers.TryGetValues("User-Agent", out IEnumerable<string> userAgents);
6666
span.PutHttpUserAgentAttribute(userAgents?.FirstOrDefault());
67+
span.PutHttpRawUrlAttribute(request.RequestUri.OriginalString);
6768

6869
this.propagationComponent.TextFormat.Inject<HttpRequestMessage>(span.Context, request, (r, k, v) => r.Headers.Add(k, v));
6970
}
@@ -84,7 +85,7 @@ public override void OnStopActivity(Activity activity, object payload)
8485
{
8586
if (requestTaskStatus != TaskStatus.RanToCompletion)
8687
{
87-
span.PutErrorAttribute();
88+
span.Status = Status.Unknown;
8889

8990
if (requestTaskStatus == TaskStatus.Canceled)
9091
{

test/OpenCensus.Collector.Dependencies.Tests/HttpClientTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ public async Task DebugIndividualTestAsync()
189189
""http.path"": ""/"",
190190
""http.method"": ""GET"",
191191
""http.host"": ""{host}:{port}"",
192-
""http.status_code"": ""404""
193-
}
192+
""http.status_code"": ""404"",
193+
""http.url"": ""http://{host}:{port}/""
194+
}
194195
}
195196
]
196197
")));

test/OpenCensus.Collector.Dependencies.Tests/http-out-test-cases.json

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
[
22
{
3-
"name": "Method GET: Successfull GET call",
3+
"name": "Successful GET call to https://example.com",
44
"method": "GET",
5-
"url": "http://{host}:{port}/",
5+
"url": "https://example.com/",
66
"spanName": "/",
77
"spanStatus": "OK",
88
"spanKind": "Client",
99
"spanAttributes": {
1010
"http.path": "/",
1111
"http.method": "GET",
12-
"http.host": "{host}:{port}",
13-
"http.status_code": "200"
12+
"http.host": "example.com",
13+
"http.status_code": "200",
14+
"http.url": "https://example.com/"
1415
}
1516
},
1617
{
17-
"name": "Method POST: Successfull POST call",
18+
"name": "Successfully POST call to https://example.com",
1819
"method": "POST",
19-
"url": "http://{host}:{port}/",
20+
"url": "https://example.com/",
2021
"spanName": "/",
2122
"spanStatus": "OK",
2223
"spanKind": "Client",
2324
"spanAttributes": {
2425
"http.path": "/",
2526
"http.method": "POST",
26-
"http.host": "{host}:{port}",
27-
"http.status_code": "200"
27+
"http.host": "example.com",
28+
"http.status_code": "200",
29+
"http.url": "https://example.com/"
2830
}
2931
},
3032
{
@@ -39,7 +41,8 @@
3941
"http.path": "/path/to/resource/",
4042
"http.method": "GET",
4143
"http.host": "{host}:{port}",
42-
"http.status_code": "200"
44+
"http.status_code": "200",
45+
"http.url": "http://{host}:{port}/path/to/resource/"
4346
}
4447
},
4548
{
@@ -53,11 +56,11 @@
5356
"http.path": "/",
5457
"http.method": "GET",
5558
"http.host": "sdlfaldfjalkdfjlkajdflkajlsdjf.sdlkjafsdjfalfadslkf.com",
56-
"error": "true"
59+
"http.url": "https://sdlfaldfjalkdfjlkajdflkajlsdjf.sdlkjafsdjfalfadslkf.com/"
5760
}
5861
},
5962
{
60-
"name": "Response code: 199. This test case is not possible to implement for some platforms as this considered an invalid status code. Fallback into 200 test case",
63+
"name": "Response code: 199. This test case is not possible to implement on some platforms as they don't allow to return this status code. Keeping this test case for visibility, but it actually simply a fallback into 200 test case",
6164
"method": "GET",
6265
"url": "http://{host}:{port}/",
6366
"responseCode": 200,
@@ -68,7 +71,8 @@
6871
"http.path": "/",
6972
"http.method": "GET",
7073
"http.host": "{host}:{port}",
71-
"http.status_code": "200"
74+
"http.status_code": "200",
75+
"http.url": "http://{host}:{port}/"
7276
}
7377
},
7478
{
@@ -83,7 +87,8 @@
8387
"http.path": "/",
8488
"http.method": "GET",
8589
"http.host": "{host}:{port}",
86-
"http.status_code": "200"
90+
"http.status_code": "200",
91+
"http.url": "http://{host}:{port}/"
8792
}
8893
},
8994
{
@@ -98,7 +103,8 @@
98103
"http.path": "/",
99104
"http.method": "GET",
100105
"http.host": "{host}:{port}",
101-
"http.status_code": "399"
106+
"http.status_code": "399",
107+
"http.url": "http://{host}:{port}/"
102108
}
103109
},
104110
{
@@ -113,7 +119,8 @@
113119
"http.path": "/",
114120
"http.method": "GET",
115121
"http.host": "{host}:{port}",
116-
"http.status_code": "400"
122+
"http.status_code": "400",
123+
"http.url": "http://{host}:{port}/"
117124
}
118125
},
119126
{
@@ -128,7 +135,8 @@
128135
"http.path": "/",
129136
"http.method": "GET",
130137
"http.host": "{host}:{port}",
131-
"http.status_code": "401"
138+
"http.status_code": "401",
139+
"http.url": "http://{host}:{port}/"
132140
}
133141
},
134142
{
@@ -143,7 +151,8 @@
143151
"http.path": "/",
144152
"http.method": "GET",
145153
"http.host": "{host}:{port}",
146-
"http.status_code": "403"
154+
"http.status_code": "403",
155+
"http.url": "http://{host}:{port}/"
147156
}
148157
},
149158
{
@@ -158,7 +167,8 @@
158167
"http.path": "/",
159168
"http.method": "GET",
160169
"http.host": "{host}:{port}",
161-
"http.status_code": "404"
170+
"http.status_code": "404",
171+
"http.url": "http://{host}:{port}/"
162172
}
163173
},
164174
{
@@ -173,7 +183,8 @@
173183
"http.path": "/",
174184
"http.method": "GET",
175185
"http.host": "{host}:{port}",
176-
"http.status_code": "429"
186+
"http.status_code": "429",
187+
"http.url": "http://{host}:{port}/"
177188
}
178189
},
179190
{
@@ -188,7 +199,8 @@
188199
"http.path": "/",
189200
"http.method": "GET",
190201
"http.host": "{host}:{port}",
191-
"http.status_code": "501"
202+
"http.status_code": "501",
203+
"http.url": "http://{host}:{port}/"
192204
}
193205
},
194206
{
@@ -203,7 +215,8 @@
203215
"http.path": "/",
204216
"http.method": "GET",
205217
"http.host": "{host}:{port}",
206-
"http.status_code": "503"
218+
"http.status_code": "503",
219+
"http.url": "http://{host}:{port}/"
207220
}
208221
},
209222
{
@@ -218,7 +231,8 @@
218231
"http.path": "/",
219232
"http.method": "GET",
220233
"http.host": "{host}:{port}",
221-
"http.status_code": "504"
234+
"http.status_code": "504",
235+
"http.url": "http://{host}:{port}/"
222236
}
223237
},
224238
{
@@ -233,7 +247,8 @@
233247
"http.path": "/",
234248
"http.method": "GET",
235249
"http.host": "{host}:{port}",
236-
"http.status_code": "600"
250+
"http.status_code": "600",
251+
"http.url": "http://{host}:{port}/"
237252
}
238253
},
239254
{
@@ -252,7 +267,8 @@
252267
"http.method": "GET",
253268
"http.host": "{host}:{port}",
254269
"http.status_code": "200",
255-
"http.user_agent": "test-user-agent"
270+
"http.user_agent": "test-user-agent",
271+
"http.url": "http://{host}:{port}/"
256272
}
257273
}
258274
]

0 commit comments

Comments
 (0)