Skip to content

fix(appinsights): propagate trace into try iframe telemetry - #393

Merged
BenjaminMichaelis merged 2 commits into
mainfrom
fix/appinsights-try-correlation
Aug 9, 2026
Merged

fix(appinsights): propagate trace into try iframe telemetry#393
BenjaminMichaelis merged 2 commits into
mainfrom
fix/appinsights-try-correlation

Conversation

@BenjaminMichaelis

Copy link
Copy Markdown
Member

Summary

  • pass the App Insights connection string into the Try iframe bootstrap config
  • initialize browser App Insights inside the Try iframe when correlation context is available
  • record iframe page view and /commands dependency telemetry under the propagated trace

Testing

  • npm test -- --grep "apiService"
  • dotnet build TryDotNet.sln -c Release

Copilot AI lite review requested due to automatic review settings August 7, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR propagates Application Insights tracing context into the Try iframe/editor so iframe telemetry (page view and /commands dependencies) can correlate with the host trace.

Changes:

  • Pass APPLICATIONINSIGHTS_CONNECTION_STRING through the editor bootstrap configuration so the iframe can initialize App Insights.
  • Initialize the App Insights browser SDK inside the iframe when correlation context is present, and emit an iframe page view.
  • Instrument /commands requests from the iframe to emit dependency telemetry under the propagated trace.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Microsoft.TryDotNet/ContentGenerator.cs Adds applicationInsightsConnectionString to the serialized editor configuration.
src/microsoft-trydotnet-editor/src/index.ts Loads/initializes App Insights in the iframe, sets trace context, and tracks page/dependency telemetry.
src/microsoft-trydotnet-editor/src/factory.ts Extends IConfiguration to include the optional App Insights connection string.
Suppressed comments (1)

src/microsoft-trydotnet-editor/src/index.ts:27

  • Indentation on this line uses spaces while the surrounding block uses tabs; this can cause noisy diffs or formatting/lint failures. Match the existing indentation style in this file.
	configureLogging({ enableLogging: configuration.enableLogging });
    void initializeAppInsights(configuration);


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +98 to +103
await ensureAppInsightsSdkLoaded();

const ApplicationInsights = getApplicationInsightsConstructor();
if (!ApplicationInsights) {
return;
}
import { configureLogging } from './log';

if (window) {
const sdkUrl = "https://js.monitor.azure.com/scripts/b/ai.3.gbl.min.js";
Comment on lines +115 to +116
appInsights.addTelemetryInitializer((item) => {
item.tags = item.tags || [];
correlationContext = correlationContextQueryValue.FirstOrDefault();
}

string? applicationInsightsConnectionString = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING");
Connection strings contain ingest credentials and must never be exposed
to untrusted clients. Removed connection string from iframe bootstrap
config to prevent data pollution and cost overruns.

Correlation still works via W3C traceparent headers: browser sends the
traceparent header in API requests, backend receives it and instruments
its own traces under the same operation ID. No credentials needed in
browser.
@BenjaminMichaelis
BenjaminMichaelis merged commit cbe0951 into main Aug 9, 2026
9 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the fix/appinsights-try-correlation branch August 9, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants