CorrelationId Class
Definition
- Namespace
- Codebelt.SharedKernel
- Assemblies
- Codebelt.SharedKernel.dll
Represents a CorrelationId object that can be used as unique identifier that help you trace requests across multiple services in a distributed system.
public record CorrelationId : Token, IEquatable<ValueObject>, IEquatable<SingleValueObject<string>>, IEquatable<Token>, IEquatable<CorrelationId>
- Inheritance
-
objectCorrelationId
- Implements
- Inherited Members
-
SingleValueObject<string>.ToString()SingleValueObject<string>.GetHashCode()SingleValueObject<string>.Equals(object)SingleValueObject<string>.Equals(ValueObject)SingleValueObject<string>.Equals(SingleValueObject<string>)SingleValueObject<string>.<Clone>$()SingleValueObject<string>.EqualityContract
Examples
The following example creates a CorrelationId from a Guid, prints the resulting trace identifier so a developer can see it at runtime, and then returns it so a downstream service can pick it up from the result. Use the implicit Guid conversion when an upstream component already produced a request id, or the string constructor when one arrives as an HTTP header.
using System;
using Codebelt.SharedKernel;
namespace DistributedTracingSample;
public static class CorrelationProbe
{
public static string EmitTrace(Guid upstreamId)
{
CorrelationId correlation = upstreamId;
var traceId = correlation.Value;
// Print the correlation id so distributed traces and logs are visible during local debugging.
Console.WriteLine(traceId);
return traceId;
}
}
Remarks
Constructors
| Name | Description |
|---|---|
| CorrelationId(Guid) | Initializes a new instance of the CorrelationId class. |
| CorrelationId(string) | Initializes a new instance of the CorrelationId class. |
Operators
| Name | Description |
|---|---|
| implicit operator CorrelationId(Guid) | Performs an implicit conversion from Guid to CorrelationId. |
| implicit operator CorrelationId(string) | Performs an implicit conversion from string to CorrelationId. |