Skip to content

Aggregate Protobuf build telemetry into a single per-build report#4575

Open
pepone wants to merge 1 commit intomainfrom
fix/protobuf-telemetry-aggregate
Open

Aggregate Protobuf build telemetry into a single per-build report#4575
pepone wants to merge 1 commit intomainfrom
fix/protobuf-telemetry-aggregate

Conversation

@pepone
Copy link
Copy Markdown
Member

@pepone pepone commented Apr 30, 2026

Fixes #4443.

Summary

The build-telemetry plug-in was running inside each per-file protoc invocation, so a project with N .proto files produced N uploads (each with FileCount=1 and a per-file hash) instead of one upload describing the whole compilation. The 3-second per-upload timeout also amplified the offline-build slowdown — N × 3 seconds when the telemetry server was unreachable.

The fix keeps the per-file fanout (which is required to produce per-file .d dependency files for incremental builds) and runs the telemetry plug-in in a separate batched protoc invocation that sees every ProtoFile in one go. The plug-in then naturally computes a single aggregate compilation hash and the correct file count, and uploads once per build.

Changes

  • Generalize ProtocTask to take a Plugins item list (each item: Identity = plug-in name, Path metadata = script path or empty for protoc built-ins) and an AdditionalOptions string array — same shape as SlicecTask.Generators / AdditionalOptions.
  • IceRpc.Protobuf.Tools.targets now invokes ProtocTask twice:
    • Once per ProtoFile (driven by Sources=\"%(_ProtoFile.Identity)\") with the csharp and icerpc-csharp plug-ins, and AdditionalOptions=\"--dependency_out=…\" to keep per-file .d files.
    • Once over all ProtoFile items with the icerpc-build-telemetry plug-in only, gated on IceRpcBuildTelemetry=true. Telemetry runs on every build (including incremental no-op builds) for analytics consistency.
  • Drop the orphaned BuildTelemetryTask UsingTask declaration left behind by Convert Protobuf build telemetry to protoc plug-in #4249.

Test plan

  • Clean build with -p:IceRpcBuildTelemetry=true: 4 .cs + 4 .IceRpc.cs + 4 .d files produced; one telemetry txt file in obj/Debug/net10.0/; server reports successful upload.
  • Clean build with -p:IceRpcBuildTelemetry=false: codegen unchanged, no telemetry call.
  • Incremental build with telemetry on (everything up-to-date): still uploads telemetry exactly once.
  • IceRpc.Protobuf.Tests: 48/48 pass.

)

The build-telemetry plug-in ran inside each per-file protoc invocation,
producing N uploads with FileCount=1 instead of one upload describing
the whole compilation.

Generalize ProtocTask to take a `Plugins` item list (matching the shape
of SlicecTask.Generators) and an `AdditionalOptions` parameter, and run
it twice from the targets: per-file for codegen plus per-file dependency
files, then once over all ProtoFile items for the telemetry plug-in.
Copilot AI review requested due to automatic review settings April 30, 2026 16:32
Copy link
Copy Markdown

Copilot AI left a comment

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 fixes Protobuf build telemetry being emitted once per .proto file by restructuring the MSBuild protoc invocations so telemetry runs in a single batched call over all ProtoFile items.

Changes:

  • Generalize ProtocTask to accept a configurable Plugins item list and AdditionalOptions.
  • Update IceRpc.Protobuf.Tools.targets to run protoc per-file for codegen (with per-file .d depfiles) and once-per-build for telemetry.
  • Remove the unused/orphaned BuildTelemetryTask UsingTask declaration.

Reviewed changes

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

File Description
src/IceRpc.Protobuf.Tools/ProtocTask.cs Refactors task to run an arbitrary set of protoc plug-ins and append extra options.
src/IceRpc.Protobuf.Tools/IceRpc.Protobuf.Tools.targets Splits protoc execution into per-file codegen and batched telemetry invocations; removes unused task registration.

Comment on lines +80 to +81
builder.AppendTextUnquoted(" ");
builder.AppendTextUnquoted(option);
BuildTelemetryPath="$(IceRpcProtocBuildTelemetryPath)"
RunBuildTelemetry="$(IceRpcBuildTelemetry)"
Plugins="@(_ProtocCodegenPlugin)"
AdditionalOptions="--dependency_out=%(_ProtoFile.OutputDir)/%(_ProtoFile.OutputFileName).d"
Copy link
Copy Markdown
Member

@externl externl left a comment

Choose a reason for hiding this comment

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

Looks good to me!

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.

[Audit-Medium] build telemetry is sent once per ProtoFile, not once p…

3 participants