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

ExceptionTelemetry clears all Context setting after setting ExceptionTelemetry.Exception #2086

Closed
ghost opened this issue Oct 7, 2020 · 5 comments
Labels

Comments

@ghost
Copy link

ghost commented Oct 7, 2020

  • Verified using version 2.14.0 (with .NET 4.5) and 2.15.0 (with .NET 4.5.2)
  • Hosting environment is Windows

Describe the bug

A new context is created in an ExceptionTelemetry instance when using the Exception property setter. This unexpectedly clears any previously set Context values from the object.

To Reproduce

$ex = new-object Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry
$ex.Context.User.AccountId = "AccountId"
$ex.Context.User.AuthenticatedUserId = "AuthUserId"
$ex.Context.User.UserAgent = "ExceptionComponent"

Write-Host "Before"
Write-Host "-----------------------------------------------------"
$ex.Context.User | fl -Force

$ex.Exception = new-object System.Exception

Write-Host "After"
Write-Host "-----------------------------------------------------"
$ex.Context.User | fl -Force

Example output:
image

Observe that in the "Before", the Context.User object is populated with values, and in the "After" it has been cleared away. Looking at the code, it looks like a brand new TelemetryContext is created when the setter for the Exception property is used.

This seems like unexpected behavior and it is not specifically called out in the API documentation. Setting the exception value from outside of the .ctor should not clear the existing Context values.

@ghost ghost added the bug label Oct 7, 2020
@avereshchak
Copy link

+1. It was totally unexpected to me after I implemented a telemetry processor which analyzes and hides sensitive exception data. I had to copy data from original context into a new one created by ExceptionTelemetry.Exception setter.

@github-actions
Copy link

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@ghost
Copy link
Author

ghost commented Oct 27, 2021

AFAICT this is still an active issue. I'm not a collaborator so I can't reopen this.

@github-actions
Copy link

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

@github-actions github-actions bot added the stale label Aug 24, 2022
@avereshchak
Copy link

It's still there. Double-checked on Microsoft.ApplicationInsight 2.21.

pharring added a commit to pharring/ApplicationInsights-dotnet that referenced this issue Aug 25, 2022
@pharring pharring removed the stale label Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants