Skip to content

Conversation

satyamz
Copy link
Contributor

@satyamz satyamz commented Aug 22, 2025

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've reviewed the changes in this PR and if I consider them worthwhile for being mentioned on release notes then I have updated the relevant CHANGELOG.md within the component folder structure. For example, if I changed horizon, then I updated (services/horizon/CHANGELOG.md. I add a new line item describing the change and reference to this PR. If I don't update a CHANGELOG, I acknowledge this PR's change may not be mentioned in future release notes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

services/friendbot: Instrument friendbot to emit traces. Traces will be sent to Grafana alloy which will send traces to Grafana tempo.

Why

  • We want to have an ability track request lifecycle
  • Help identify performance bottlenecks.

Known limitations

This PR updates several dependencies. We need land this carefully.

Issue:

https://github.com/stellar/ops/issues/4005

Copy link

socket-security bot commented Aug 22, 2025

@satyamz satyamz marked this pull request as ready for review September 10, 2025 14:47
@Copilot Copilot AI review requested due to automatic review settings September 10, 2025 14:47
Copy link

@Copilot 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 instruments the friendbot service to emit OpenTelemetry traces that will be sent to Grafana Alloy and forwarded to Grafana Tempo for distributed tracing capabilities and performance monitoring.

  • Added a new utils/tracer package with OpenTelemetry configuration
  • Updated friendbot service to use context-aware tracing throughout the request lifecycle
  • Added OpenTelemetry middleware to the HTTP router for automatic request tracing

Reviewed Changes

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

Show a summary per file
File Description
utils/tracer/tracer.go New utility package for OpenTelemetry tracer initialization and configuration
services/friendbot/main.go Updated to initialize tracing, add OpenTelemetry middleware, and use chi/v5 router
services/friendbot/internal/friendbot_handler.go Added tracing instrumentation to HTTP request handlers
services/friendbot/internal/friendbot.go Updated Pay method to accept context for tracing
services/friendbot/internal/minion.go Added context parameter and span instrumentation to minion operations
services/friendbot/internal/minion_test.go Updated test functions to pass context parameter
services/friendbot/internal/friendbot_test.go Updated test functions to pass context parameter
services/friendbot/friendbot.cfg Added otel_endpoint configuration
go.mod Updated dependencies to include OpenTelemetry packages and chi/v5

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

)

if err != nil {
return nil, errors.Wrap(err, "failed to create exporter")
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The error message 'failed to create exporter' is inconsistent with the previous error message on line 50 which says 'Error while creating exporter'. Consider using consistent messaging and grammar.

Suggested change
return nil, errors.Wrap(err, "failed to create exporter")
return nil, errors.Wrap(err, "Error while creating resource")

Copilot uses AI. Check for mistakes.

Comment on lines +26 to 28
serviceVersion = "1.0.0" //TODO: Change version
)

Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The TODO comment suggests this hardcoded version should be changed. Consider using build-time injection or reading from a version file to make version management more maintainable.

Suggested change
serviceVersion = "1.0.0" //TODO: Change version
)
)
// serviceVersion should be set at build time using -ldflags "-X main.serviceVersion=1.2.3"
var serviceVersion = "dev"

Copilot uses AI. Check for mistakes.

@@ -63,6 +72,15 @@ func run(cmd *cobra.Command, args []string) {
os.Exit(1)
}

//Setup and intialize tracer
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

Spelling error: 'intialize' should be 'initialize'.

Suggested change
//Setup and intialize tracer
//Setup and initialize tracer

Copilot uses AI. Check for mistakes.

address := r.Form.Get("addr")
if address == "" {
span.SetStatus(codes.Error, "missing destination account address")
span.SetAttributes(attribute.String("error.type", "missing_parameter"))
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

This condition sets span status to error but doesn't return early, allowing execution to continue with an empty address which will likely cause issues downstream. The function should return an error when address is empty.

Suggested change
span.SetAttributes(attribute.String("error.type", "missing_parameter"))
span.SetAttributes(attribute.String("error.type", "missing_parameter"))
return "", problem.MakeInvalidFieldProblem("addr", nil)

Copilot uses AI. Check for mistakes.

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