Skip to content
Merged
Changes from 5 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
63 changes: 63 additions & 0 deletions content/en/data_streams/manual_instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,69 @@ set_consume_checkpoint(
"<datastream-type>", "<datastream-name>", headers.get
)

{{< /code-block >}}
{{% /tab %}}
{{% tab ".Net" %}}
<div class="alert alert-warning">
<strong>Note:</strong> DSM instrumentation does not work in Async operations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this wording is not too strong... It will work, it's just that context is broken/lost on a send following a receive. I don't know how to convey that in a clear way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does:

Note: 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.

Sound?

</div>

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

using (var scope = Tracer.Instance.StartActive("produce"))
{
var headers = new Headers();
var msg = new Message<Null, string> { Value = "any kind of 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 >}}

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

var msg = consumer.Consume();
var parentContext = new SpanContextExtractor().ExtractIncludingDsm(
msg.Headers,
GetHeader,
messageType: "<datastream-type>",
source: "<queue-or-topic-name>"
);
var startTime = DateTimeOffset.UtcNow;

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 >}}
{{% /tab %}}
{{< /tabs >}}
Expand Down
Loading