Improved OBO logging and added OBO observability to SESSION_CONTEXT#3192
Improved OBO logging and added OBO observability to SESSION_CONTEXT#3192anushakolan wants to merge 11 commits intomainfrom
Conversation
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR improves observability for user-delegated (OBO) authentication by enhancing OBO token acquisition logging and by adding OpenTelemetry correlation + OBO identity details into SQL Server SESSION_CONTEXT when set-session-context is enabled.
Changes:
- Add structured OBO token logging in
OboSqlTokenProviderwith event types andtraceIdcorrelation. - Extend
MsSqlQueryExecutor.GetSessionParamsQueryto setdab.trace_id,dab.span_id,dab.auth_type,dab.user_id, anddab.tenant_idinSESSION_CONTEXT. - Add unit tests validating inclusion/exclusion of correlation IDs and OBO observability session-context values.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Service.Tests/UnitTests/SqlQueryExecutorUnitTests.cs | Adds unit tests for new session-context observability values and Activity correlation behavior. |
| src/Core/Resolvers/OboSqlTokenProvider.cs | Adds structured log fields (EventType + traceId) for OBO validation/cache/acquisition events. |
| src/Core/Resolvers/MsSqlQueryExecutor.cs | Writes OpenTelemetry correlation IDs and OBO identity markers into SQL Server SESSION_CONTEXT. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
Aniruddh25
left a comment
There was a problem hiding this comment.
OBO should trace irrespective of set-session-context values.
|
/azp run |
|
Azure Pipelines successfully started running 6 pipeline(s). |
| { | ||
| _logger.LogWarning("Cannot acquire OBO token: ClaimsPrincipal is null."); | ||
| _logger.LogWarning( | ||
| "{EventType}: Cannot acquire OBO token - ClaimsPrincipal is null (traceId: {TraceId}).", |
There was a problem hiding this comment.
Should we use an enum for the EventType instead of just providing a string?
|
DAB currently has its own correlation system, which adds a correlation ID to the DAB logs. So if a user were to get say a 500 error on a REST call they would have in the DAB logs a correlation id associated with the error. The dab logs would also show the Obo Token being acquired with a separate traceid. But in the SQL Server session context, there will only be the trace id, not the dab correlation id. So in order to connect the dab error log to the SQL audit, the user would have to go through some sort of APM tool to match the requests by timestamp, or theyd need to know that both IDs belong to the same http request. If the dab.correlation_id was also included in the SESSION_CONTEXT, then the user could directly join the SQL audit log to the DAB error log without needing to use any other tools. This might be particularly useful if there are different people or teams looking at the different logs. Not a blocker, but something I think we should consider. |
| if (currentActivity is not null) | ||
| { | ||
| string traceIdParamName = $"{SESSION_PARAM_NAME}{counter.Next()}"; | ||
| parameters.Add(traceIdParamName, new(currentActivity.TraceId.ToString())); |
There was a problem hiding this comment.
Because of our retry policy in query executor, a transient fault may end up trying to re-add params that already exist in this dictionary, which would error out. This is an already existing issue however, and I dont think Ive seen this show up yet, but figured it is worth flagging, and i think can be fixed by changing from .add to using an indexer; parameters[traceIdParamName]=foo
aaronburtle
left a comment
There was a problem hiding this comment.
Looks good! Couple comments, but no blockers.
Why make this change?
Closes #3125
What is this change?
Added the following values to SQL Server SESSION_CONTEXT when set-session-context is enabled:
How was this tested?
Unit Tests
Manual E2E Testing