Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update manual_instrumentation.md adding .Net entry #27424

Merged
merged 22 commits into from
Feb 7, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
195fad8
Update manual_instrumentation.md adding .Net entry
gitstevenpham Feb 3, 2025
11b5514
remove "will"
gitstevenpham Feb 3, 2025
6aa7930
copy change
gitstevenpham Feb 3, 2025
04a76cd
fix typo
gitstevenpham Feb 3, 2025
d3b2ed1
update code example
gitstevenpham Feb 3, 2025
d5f590f
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 3, 2025
1c118c5
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 3, 2025
ee78b6a
Update note about async
gitstevenpham Feb 3, 2025
21d4b50
Update Trace Context Propagation section
gitstevenpham Feb 3, 2025
ded8f93
Fix link syntax
gitstevenpham Feb 3, 2025
13ba663
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 4, 2025
81f343e
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 4, 2025
8a0256a
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 4, 2025
6ada0ab
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 4, 2025
492fadd
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 4, 2025
7757875
Update content/en/data_streams/manual_instrumentation.md
gitstevenpham Feb 4, 2025
043e0ae
Update manual_instrumentation.md
gitstevenpham Feb 4, 2025
b7ec528
Update manual_instrumentation.md
gitstevenpham Feb 4, 2025
d399624
Update manual_instrumentation.md
gitstevenpham Feb 4, 2025
f41664d
attempt to fix links
gitstevenpham Feb 5, 2025
d1cd30e
Update manual_instrumentation.md
gitstevenpham Feb 6, 2025
6389be1
Fix reference link
buraizu Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions content/en/data_streams/manual_instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,75 @@

{{< /code-block >}}
{{% /tab %}}
{{% tab ".Net" %}}
The following example propagates the trace context. See [Trace Context Propagation][1] for more information.

<div class="alert alert-warning">
<strong>Note:</strong> In async operations, this may not work as expected because the context derived from the incoming message can be lost when producing a new message in different threads.

Check notice on line 103 in content/en/data_streams/manual_instrumentation.md

View workflow job for this annotation

GitHub Actions / vale

Datadog.sentencelength

Suggestion: Try to keep your sentence length to 25 words or fewer.
</div>

#### Producer configuration

{{< code-block lang="csharp" >}}
using Datadog.Trace;

using (var scope = Tracer.Instance.StartActive("produce"))
{
var headers = new Headers();
var msg = new Message { Value = "<ANY-VALUE>", Headers = headers};

new SpanContextInjector().InjectIncludingDsm(
msg.Headers,
SetHeader,
scope.Span.Context,
messageType: "<DATASTREAM-TYPE>",
target: "<QUEUE-OR-TOPIC-NAME>"
);

// Produce the message
}

// Specific to how the header is modeled
static void SetHeader(Headers headers, string key, string value)
{
headers.Add(new Header(key, value));
}
{{< /code-block >}}

#### Consumer configuration

{{< code-block lang="csharp" >}}
using Datadog.Trace;

var startTime = DateTimeOffset.UtcNow;
var msg = consumer.Consume();
var parentContext = new SpanContextExtractor().ExtractIncludingDsm(
msg.Headers,
GetHeader,
messageType: "<DATASTREAM-TYPE>",
source: "<QUEUE-OR-TOPIC-NAME>"
);

using (var scope = Tracer.Instance.StartActive("consume",
new SpanCreationSettings,
{
Parent = parentContext,
StartTime = startTime
})
)
{
// Do something with the message
}

// Specific to how the header is modeled
static IEnumerable<string?> GetHeader(Headers headers, string key)
{
yield return header.GetByKey(key);
}
{{< /code-block >}}

[1]: /tracing/trace_collection/trace_context_propagation/?tab=net#additional-use-cases
{{% /tab %}}
{{< /tabs >}}
## Further Reading

Expand Down
Loading