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

feat: add operation parent generate id option #415

Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions docs/preview/02-Features/correlation.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ public void ConfigureServices(IServiceCollection services)
// The function that will generate the operation ID header value.
// (default: new `Guid`).
options.Operation.GenerateId = () => $"Operation-{Guid.NewGuid()}";

// Configuration on the operation parent ID.
// -----------------------------------------

// Whether to extract the operation parent ID from the request or not (default: true).
options.OperationParent.ExtractFromRequest = false;

// The header that will contain the full operation parent ID (default: Request-Id).
options.OperationParent.OperationParentHeaderName = "Request-Id";

// The function that will generate the operation parent ID when it shouldn't be extracted from the request.
options.OperationParent.GenerateId = () => $"Parent-{Guid.newGuid()}";
});
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Arcus.Observability.Correlation
public class CorrelationInfoUpstreamServiceOptions
{
private string _operationParentIdHeaderName = "Request-Id";
private Func<string> _generateId = () => Guid.NewGuid().ToString();

/// <summary>
/// Gets or sets the flag indicating whether or not the upstream service information should be extracted from the <see cref="OperationParentIdHeaderName"/> following the W3C Trace-Context standard.
Expand All @@ -28,5 +29,19 @@ public string OperationParentIdHeaderName
_operationParentIdHeaderName = value;
}
}

/// <summary>
/// Gets or sets the function to generate the operation parent ID without extracting from the request.
/// </summary>
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="value"/> is <c>null</c>.</exception>
public Func<string> GenerateId
{
get => _generateId;
set
{
Guard.NotNull(value, nameof(value), "Requires a function to generate the operation parent ID");
_generateId = value;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,15 @@ public void SetOperationParentIdPropertyName_WithBlankValue_Fails(string operati
Assert.ThrowsAny<ArgumentException>(() =>
options.OperationParent.OperationParentIdHeaderName = operationIdPropertyName);
}

[Fact]
public void OperationParentId_WithoutGeneration_Fails()
{
// Arrange
var options = new CorrelationInfoOptions();

// Act / Assert
Assert.ThrowsAny<ArgumentException>(() => options.OperationParent.GenerateId = null);
}
}
}