Skip to content

Apply sample rate to all profiler subsystem telemetry to bypass ingestion sampling#4786

Open
johnoliver wants to merge 7 commits into
microsoft:mainfrom
johnoliver:fix-sampling
Open

Apply sample rate to all profiler subsystem telemetry to bypass ingestion sampling#4786
johnoliver wants to merge 7 commits into
microsoft:mainfrom
johnoliver:fix-sampling

Conversation

@johnoliver

Copy link
Copy Markdown
Member

This pull request ensures that specific telemetry events (GcEvent, ServiceProfilerIndex, and certain message telemetry) are emitted with a sample rate that bypasses ingestion sampling, guaranteeing they are always ingested. It also makes the sample rate constant publicly accessible and adds a targeted unit test to verify this behavior.

Telemetry sampling changes:

  • Set the sample rate for GcEvent, ServiceProfilerIndex, and related message telemetry to SamplerUtil.SAMPLE_RATE_TO_DISABLE_INGESTION_SAMPLING, ensuring these events bypass ingestion sampling (AlertingSubsystemInit.java, GcEventInit.java). [1] [2] [3]
  • Made SAMPLE_RATE_TO_DISABLE_INGESTION_SAMPLING a public constant in SamplerUtil for use across modules (SamplerUtil.java).

Testing improvements:

  • Added a unit test in GcEventInitTest.java to verify that GcEvent telemetry is emitted with the correct sample rate, including supporting test utilities and mocks (GcEventInitTest.java). [1] [2]

Dependency updates:

  • Updated import statements to include SamplerUtil where needed (AlertingSubsystemInit.java, GcEventInit.java, GcEventInitTest.java). [1] [2] [3]

…stion sampling

    Make SAMPLE_RATE_TO_DISABLE_INGESTION_SAMPLING public and set it on the
    ServiceProfilerIndex event, the StartProfiler/StopProfiler messages, and
    GcEvent telemetry. These events are emitted directly via TelemetryClient
    (not through the trace sampler), so previously they had no sample rate set,
    leaving them eligible for backend ingestion sampling. Using 99.99 keeps the
    item count at 1 while ensuring the events are not dropped.

    Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the profiler subsystem’s telemetry emission to explicitly set a sample rate intended to bypass ingestion-time sampling, ensuring key profiler-related events (GC events, ServiceProfilerIndex, and certain message telemetry) are always ingested. It also exposes the shared “disable ingestion sampling” sample-rate constant and adds a unit test to validate the GC event behavior.

Changes:

  • Set sampleRate on GcEvent, ServiceProfilerIndex, and selected message telemetry to SamplerUtil.SAMPLE_RATE_TO_DISABLE_INGESTION_SAMPLING.
  • Expose SAMPLE_RATE_TO_DISABLE_INGESTION_SAMPLING as a public constant for reuse across modules.
  • Add a targeted unit test to assert GcEvent telemetry is emitted with the expected sample rate.

Reviewed changes

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

File Description
agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/GcEventInitTest.java Adds a unit test that observes emitted GcEvent telemetry and asserts the sample rate used to bypass ingestion sampling.
agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/SamplerUtil.java Makes the “disable ingestion sampling” sample-rate constant publicly accessible for shared use.
agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/GcEventInit.java Applies the bypass-ingestion sample rate to emitted GcEvent telemetry.
agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/profiler/triggers/AlertingSubsystemInit.java Applies the bypass-ingestion sample rate to ServiceProfilerIndex and message telemetry emitted by the alerting/profiler init path.

johnoliver and others added 6 commits July 10, 2026 15:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ervers

Root cause: TelemetryClient.trackAsync() returns early when connectionString
is null, before notifying TelemetryObservers. The test built a TelemetryClient
without a connection string, so the observer CompletableFuture was never
completed, causing TimeoutException.

Fix: supply a dummy connection string in the test builder so trackAsync()
proceeds past the null check and correctly fires the registered observer.

Test-only change; production code is unmodified.
Stabilize GcEventInitTest: fix deterministic TimeoutException in agent-tooling CI
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.

3 participants