Skip to content

feat: add OTel#322

Draft
janishorsts wants to merge 24 commits intomainfrom
feat-otel
Draft

feat: add OTel#322
janishorsts wants to merge 24 commits intomainfrom
feat-otel

Conversation

@janishorsts
Copy link
Collaborator

@janishorsts janishorsts commented Feb 4, 2026

WIP

Description

When the TRACEPARENT (W3C Trace Context format) environment variable is set, it is used as the parent span.

TODO

These may or may not be part of this feat.

  • Do not send telemetry by default.
  • Make phases (Init, Build, Output) as parent spans? Or remove the phases? REMOVED
  • Read span parent from the environment

Screenshot

Screenshot 2026-02-04 at 21 54 36

@github-actions
Copy link

github-actions bot commented Feb 4, 2026

➖ Are we earthbuild yet?

No change in "earthly" occurrences

📈 Overall Progress

Branch Total Count
main 5658
This PR 5658
Difference +0

Keep up the great work migrating from Earthly to Earthbuild! 🚀

💡 Tips for finding more occurrences

Run locally to see detailed breakdown:

./.github/scripts/count-earthly.sh

Note that the goal is not to reach 0.
There is anticipated to be at least some occurences of earthly in the source code due to backwards compatibility with config files and language constructs.

@gemini-code-assist
Copy link

Summary of Changes

Hello @janishorsts, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request lays the groundwork for enhanced observability within the EarthBuild project by integrating OpenTelemetry. It establishes a robust framework for collecting and exporting telemetry data, including traces, metrics, and logs, from critical application workflows. This foundational change will provide developers with deeper insights into the application's runtime behavior and performance characteristics, facilitating debugging and optimization efforts.

Highlights

  • OpenTelemetry Integration: Introduced OpenTelemetry for comprehensive observability, enabling distributed tracing, metrics collection, and structured logging across key components of the application.
  • Centralized Telemetry Setup: A new internal/telemetry package has been added to centralize the configuration and management of the OpenTelemetry pipeline, including tracer, meter, and logger providers with auto-export capabilities.
  • Automated Tracing of Core Operations: Key build phases (PhaseBuild, PhaseOutput, PhaseInit) and the main application execution (main function) are now automatically instrumented with OpenTelemetry spans to capture performance data.
  • Dependency Updates: Numerous Go module dependencies have been added or updated, primarily to support the OpenTelemetry integration and ensure compatibility with the latest versions of related libraries.
Changelog
  • builder/builder.go
    • Imported internal/telemetry package.
    • Added OpenTelemetry tracing spans for PhaseBuild and PhaseOutput within the convertAndBuild function.
  • cmd/earthly/main.go
    • Imported internal/telemetry and go.opentelemetry.io/otel/semconv.
    • Initialized the OpenTelemetry pipeline and configured a shutdown hook in the run function.
    • Added a main OpenTelemetry span for the application's execution and set the process exit code as an attribute.
    • Refactored error variable declarations to reuse err for f.Apply and godotenv.Load calls.
    • Simplified the return statement for earthly.Run.
  • cmd/earthly/subcmd/build_cmd.go
    • Imported internal/telemetry package.
    • Added an OpenTelemetry tracing span for builder.PhaseInit within the ActionBuildImp function.
  • earthfile2llb/converter.go
    • Removed context.Context from the NewConverter function signature.
  • earthfile2llb/earthfile2llb.go
    • Imported internal/telemetry package.
    • Added an OpenTelemetry tracing span for the Earthfile2LLB function, dynamically named after the target.
    • Updated the call to NewConverter to reflect the modified function signature.
  • go.mod
    • Added core OpenTelemetry modules (go.opentelemetry.io/otel, go.opentelemetry.io/otel/sdk, go.opentelemetry.io/otel/sdk/log, go.opentelemetry.io/otel/sdk/metric, go.opentelemetry.io/otel/log).
    • Added OpenTelemetry contrib modules (go.opentelemetry.io/contrib/exporters/autoexport, go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc, go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp, go.opentelemetry.io/contrib/bridges/prometheus).
    • Updated google.golang.org/grpc and google.golang.org/protobuf versions.
    • Updated various indirect dependencies including github.com/felixge/httpsnoop, github.com/grpc-ecosystem/grpc-gateway/v2, github.com/klauspost/compress, github.com/prometheus/*, golang.org/x/exp, golang.org/x/net, golang.org/x/time.
  • go.sum
    • Updated checksums for all modified and newly added Go modules to reflect changes in go.mod.
  • internal/telemetry/telemetry.go
    • New file: Implemented the core OpenTelemetry setup logic.
    • Defined Tracer() to provide the application's tracer instance.
    • Implemented Setup() to initialize the OpenTelemetry pipeline, including propagator, tracer provider, meter provider, and logger provider.
    • Configured resource attributes for the service, process command, PID, and executable path.
    • Provided helper functions (newTracerProvider, newMeterProvider, newLoggerProvider) for configuring specific OpenTelemetry providers with auto-export capabilities.
Activity
  • The pull request is currently marked as 'Work In Progress' (WIP).
  • A TODO item exists to implement a mechanism to prevent telemetry from being sent by default.
  • A screenshot has been provided, likely demonstrating the initial telemetry output or integration.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces OpenTelemetry to the project, which is a great step towards better observability. The implementation in the new internal/telemetry package is a solid foundation, especially with the use of autoexport for flexible configuration. However, I've found a few critical issues related to span management that could lead to incorrect traces, such as leaked spans and double-ending spans. There are also a couple of minor points in the new telemetry package concerning error handling and logging that could be improved. Please see the detailed comments for specifics.

@janishorsts janishorsts self-assigned this Feb 8, 2026
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.

1 participant