Skip to content

Commit cb55185

Browse files
authored
[Azure.Messaging.EventGrid.Namespaces] Add trace context to distributed tracing (Azure#49485)
* p1 * update * implementation * second pass * tweaks to cloudeventrequestcontent * reformat tests p1 * tests * fix request content * split types
1 parent c5d115d commit cb55185

File tree

8 files changed

+662
-20
lines changed

8 files changed

+662
-20
lines changed

sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/samples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ description: Samples for the Azure.Messaging.EventGrid.Namespaces client library
1313
Before starting, take a look at the Azure Event Grid [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/README.md) for more information on how to create an Event Grid custom topic or domain using the Azure portal/Azure CLI, and retrieving the designated endpoint and credential.
1414

1515
- [Using Namespace Topics](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/samples/Sample1_Namespaces.md)
16-
- [Using the Cloud Native CloudEvent type]
16+
- [Using the Cloud Native CloudEvent type](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/samples/Sample2_CNCF.md)

sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/src/Azure.Messaging.EventGrid.Namespaces.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
<DisableEnhancedAnalysis>true</DisableEnhancedAnalysis>
1212
</PropertyGroup>
1313

14-
<ItemGroup>
14+
<ItemGroup>
15+
<Compile Include="$(AzureCoreSharedSources)AzureKeyCredentialPolicy.cs" LinkBase="Shared/Core" />
1516
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="Shared/Core" />
16-
<Compile Include="..\..\..\core\Azure.Core\src\Shared\AzureKeyCredentialPolicy.cs">
17-
<Link>Shared\Core\AzureKeyCredentialPolicy.cs</Link>
18-
</Compile>
1917
</ItemGroup>
2018

2119
<ItemGroup>
20+
<Compile Include="$(AzureEventGridSharedSources)CloudEventRequestContent.cs" LinkBase="Shared/EventGrid" />
21+
<Compile Include="$(AzureEventGridSharedSources)CloudEventsRequestContent.cs" LinkBase="Shared/EventGrid" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
2225
<PackageReference Include="Azure.Core" />
2326
</ItemGroup>
2427

sdk/eventgrid/Azure.Messaging.EventGrid.Namespaces/src/Customization/EventGridSenderClient.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Azure.Messaging.EventGrid.Namespaces
1818
public partial class EventGridSenderClient
1919
{
2020
private readonly string _topicName;
21+
private readonly bool _isDistributedTracingEnabled;
2122

2223
/// <summary> Initializes a new instance of EventGridSenderClient. </summary>
2324
/// <param name="endpoint"> The host name of the namespace, e.g. namespaceName1.westus-1.eventgrid.azure.net. </param>
@@ -66,6 +67,7 @@ public EventGridSenderClient(Uri endpoint,
6667
_endpoint = endpoint;
6768
_apiVersion = options.Version;
6869
_topicName = topicName;
70+
_isDistributedTracingEnabled = options.Diagnostics.IsDistributedTracingEnabled;
6971
}
7072

7173
/// <summary> Initializes a new instance of EventGridSenderClient. </summary>
@@ -93,6 +95,7 @@ public EventGridSenderClient(Uri endpoint,
9395
_endpoint = endpoint;
9496
_apiVersion = options.Version;
9597
_topicName = topicName;
98+
_isDistributedTracingEnabled = options.Diagnostics.IsDistributedTracingEnabled;
9699
}
97100

98101
/// <summary> Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. </summary>
@@ -104,7 +107,7 @@ public virtual Response Send(CloudEvent cloudEvent, CancellationToken cancellati
104107
Argument.AssertNotNull(cloudEvent, nameof(cloudEvent));
105108

106109
RequestContext context = FromCancellationToken(cancellationToken);
107-
return Send(_topicName, RequestContent.Create(cloudEvent), context);
110+
return Send(_topicName, new CloudEventRequestContent(cloudEvent, _isDistributedTracingEnabled), context);
108111
}
109112

110113
/// <summary> Publish Single Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. </summary>
@@ -118,7 +121,7 @@ public virtual async Task<Response> SendAsync(
118121
Argument.AssertNotNull(cloudEvent, nameof(cloudEvent));
119122

120123
RequestContext context = FromCancellationToken(cancellationToken);
121-
return await SendAsync(_topicName, RequestContent.Create(cloudEvent), context).ConfigureAwait(false);
124+
return await SendAsync(_topicName, new CloudEventRequestContent(cloudEvent, _isDistributedTracingEnabled), context).ConfigureAwait(false);
122125
}
123126

124127
/// <summary> Publish Batch Cloud Event to namespace topic. In case of success, the server responds with an HTTP 200 status code with an empty JSON object in response. Otherwise, the server can return various error codes. For example, 401: which indicates authorization failure, 403: which indicates quota exceeded or message is too large, 410: which indicates that specific topic is not found, 400: for bad request, and 500: for internal server error. </summary>
@@ -136,7 +139,7 @@ public virtual async Task<Response> SendAsync(IEnumerable<CloudEvent> cloudEvent
136139
scope.Start();
137140
try
138141
{
139-
return await SendEventsAsync(_topicName, RequestContent.Create(cloudEvents), context).ConfigureAwait(false);
142+
return await SendEventsAsync(_topicName, new CloudEventsRequestContent(cloudEvents, _isDistributedTracingEnabled), context).ConfigureAwait(false);
140143
}
141144
catch (Exception e)
142145
{
@@ -160,7 +163,7 @@ public virtual Response Send(IEnumerable<CloudEvent> cloudEvents, CancellationTo
160163
scope.Start();
161164
try
162165
{
163-
return SendEvents(_topicName, RequestContent.Create(cloudEvents), context);
166+
return SendEvents(_topicName, new CloudEventsRequestContent(cloudEvents, _isDistributedTracingEnabled), context);
164167
}
165168
catch (Exception e)
166169
{

0 commit comments

Comments
 (0)