Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit ae23f7c

Browse files
author
Praburaj
committed
Adding a feature to get the traceidentifier for a request
Addresses : #117 Related changes in Helios & weblistener in separate PRs.
1 parent de1e876 commit ae23f7c

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.AspNet.Http.Interfaces
7+
{
8+
/// <summary>
9+
/// Feature to identify a request.
10+
/// </summary>
11+
public interface IRequestIdentifierFeature
12+
{
13+
/// <summary>
14+
/// Identifier to trace a request.
15+
/// </summary>
16+
Guid TraceIdentifier { get; }
17+
}
18+
}

src/Microsoft.AspNet.Owin/OwinConstants.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ internal static class OwinConstants
2020

2121
#endregion
2222

23+
#region OWIN v1.1.0 - 3.2.1 Request Data
24+
25+
// OWIN 1.1.0 http://owin.org/html/owin.html
26+
27+
public const string RequestId = "owin.RequestId";
28+
29+
#endregion
30+
2331
#region OWIN v1.0.0 - 3.2.2. Response Data
2432

2533
// http://owin.org/spec/owin-1.0.0.html

src/Microsoft.AspNet.Owin/OwinEnvironment.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public OwinEnvironment(HttpContext context)
8080
{ OwinConstants.Security.User, new FeatureMap<IHttpAuthenticationFeature>(feature => feature.User,
8181
()=> null, (feature, value) => feature.User = Utilities.MakeClaimsPrincipal((IPrincipal)value),
8282
() => new HttpAuthenticationFeature())
83-
},
83+
}
8484
};
8585

8686
// owin.CallCancelled is required but the feature may not be present.
@@ -113,6 +113,9 @@ public OwinEnvironment(HttpContext context)
113113
}
114114

115115
_context.Items[typeof(HttpContext).FullName] = _context; // Store for lookup when we transition back out of OWIN
116+
117+
// The request identifier is a string per the spec.
118+
_entries[OwinConstants.RequestId] = new FeatureMap<IRequestIdentifierFeature>(feature => feature.TraceIdentifier.ToString());
116119
}
117120

118121
// Public in case there's a new/custom feature interface that needs to be added.
@@ -369,7 +372,7 @@ public FeatureMap(Func<TFeature, object> getter, Action<TFeature, object> setter
369372
}
370373

371374
public FeatureMap(Func<TFeature, object> getter, Func<object> defaultFactory, Action<TFeature, object> setter)
372-
: base(typeof(TFeature), feature => getter((TFeature)feature), defaultFactory,(feature, value) => setter((TFeature)feature, value))
375+
: base(typeof(TFeature), feature => getter((TFeature)feature), defaultFactory, (feature, value) => setter((TFeature)feature, value))
373376
{
374377
}
375378

src/Microsoft.AspNet.Owin/OwinFeatureCollection.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public class OwinFeatureCollection :
3232
IHttpRequestLifetimeFeature,
3333
IHttpAuthenticationFeature,
3434
IHttpWebSocketFeature,
35-
IOwinEnvironmentFeature
35+
IOwinEnvironmentFeature,
36+
IRequestIdentifierFeature
3637
{
3738
public IDictionary<string, object> Environment { get; set; }
3839
private bool _headersSent;
@@ -427,6 +428,22 @@ public bool IsReadOnly
427428
get { return true; }
428429
}
429430

431+
Guid IRequestIdentifierFeature.TraceIdentifier
432+
{
433+
get
434+
{
435+
var requestId = Prop<string>(OwinConstants.RequestId);
436+
Guid requestIdentifier;
437+
438+
if (requestId != null && Guid.TryParse(requestId, out requestIdentifier))
439+
{
440+
return requestIdentifier;
441+
}
442+
443+
return Guid.Empty;
444+
}
445+
}
446+
430447
public bool Remove(KeyValuePair<Type, object> item)
431448
{
432449
throw new NotSupportedException();

0 commit comments

Comments
 (0)