Skip to content

Add traceStateValue parameter to DistributedTracingData.TryDeserializ… #2607

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
32 changes: 27 additions & 5 deletions src/Elastic.Apm/Api/DistributedTracingData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@ internal DistributedTracingData(string traceId, string parentId, bool flagRecord
internal TraceState TraceState { get; }

/// <summary>
/// Serializes this instance to a string.
/// This method should be used at the caller side and the return value should be passed to the (possibly remote) callee
/// side.
/// <see cref="TryDeserializeFromString" /> should be used to deserialize the instance at the callee side.
/// Serializes this instance to a traceparent string.
/// This method should be used at the caller side in pairs with <see cref="SerializeTraceStateToString" />,
/// and the return value should be passed to the (possibly remote) callee side.
/// <see cref="Create" /> should be used to deserialize the instance at the callee side.
/// </summary>
/// <returns>
/// String containing the instance in serialized form.
/// String containing the traceparent data in serialized form.
/// </returns>
public string SerializeToString() => TraceContext.BuildTraceparent(this);

/// <summary>
/// Serializes this instance to a tracestate string.
/// This method should be used at the caller side in pairs with <see cref="SerializeToString" />,
/// and the return value should be passed to the (possibly remote) callee side.
/// <see cref="Create" /> should be used to deserialize the instance at the callee side.
/// </summary>
/// <returns>The string representation of the tracestate header, or null if there is no tracestate.</returns>
public string SerializeTraceStateToString() => TraceState?.ToTextHeader();

/// <summary>
/// Deserializes an instance from a string.
/// This method should be used at the callee side and the deserialized instance can be passed to
Expand All @@ -54,6 +63,19 @@ internal DistributedTracingData(string traceId, string parentId, bool flagRecord
/// </returns>
public static DistributedTracingData TryDeserializeFromString(string serialized) => TraceContext.TryExtractTracingData(serialized);

/// <summary>
/// Creates an instance from a treceparent and tracestate strings.
/// This method should be used at the callee side, and the created instance can be passed to
/// <see cref="ITracer.StartTransaction" />.
/// </summary>
/// <param name="traceParent">should be a return value from a call to <see cref="SerializeToString" />.</param>
/// <param name="traceState">should be a return value from a call to <see cref="SerializeTraceStateToString"/>.</param>
/// <returns>
/// Instance deserialized from <paramref name="traceParent" /> and <paramref name="traceState" /> .
/// </returns>
public static DistributedTracingData Create(string traceParent, string traceState) =>
TraceContext.TryExtractTracingData(traceParent, traceState);

public override string ToString() => new ToStringBuilder(nameof(DistributedTracingData))
{
{ nameof(TraceId), TraceId },
Expand Down