Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow metrics to be sync #2433

Merged
merged 1 commit into from
Apr 3, 2024
Merged

Allow metrics to be sync #2433

merged 1 commit into from
Apr 3, 2024

Conversation

trajan0x
Copy link
Contributor

@trajan0x trajan0x commented Apr 3, 2024

Description

Allow spans to be sync by setting an environment variable

Summary by CodeRabbit

  • New Features
    • Introduced an environment variable to control metric synchronization behavior, enhancing the flexibility of metric exports.

Copy link
Contributor

coderabbitai bot commented Apr 3, 2024

Walkthrough

This update introduces an environment variable, METRICS_ALWAYS_SYNC, designed to ensure metrics are exported synchronously before a span concludes. It modifies the metric system's behavior, adding a condition that, when METRICS_ALWAYS_SYNC is true, incorporates an AlwaysSample() sampler. This adjustment aims to enhance the control over metric synchronization during span termination.

Changes

File Change Summary
core/metrics/... Introduced METRICS_ALWAYS_SYNC to control metric export synchronization. Added conditional AlwaysSample() sampler.

🐇✨

In the realm of code, where metrics align,
A rabbit hopped in, with an idea so fine.
"Let's sync our metrics, before the end," it said,
With a variable, our paths we'll thread.
Now spans close, with data in sync,
A hop, a leap, in less than a blink.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Apr 3, 2024
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 46.93851%. Comparing base (9218a0b) to head (25fa52c).

Files Patch % Lines
core/metrics/base.go 0.00000% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2433         +/-   ##
===================================================
- Coverage   46.94226%   46.93851%   -0.00375%     
===================================================
  Files            383         400         +17     
  Lines          29270       30655       +1385     
  Branches          83          83                 
===================================================
+ Hits           13740       14389        +649     
- Misses         14069       14733        +664     
- Partials        1461        1533         +72     
Flag Coverage Δ
cctp-relayer 43.53414% <ø> (?)
committee 63.04654% <ø> (ø)
core 64.42846% <0.00000%> (-0.19739%) ⬇️
ethergo 60.54759% <ø> (+0.01836%) ⬆️
explorer 24.80122% <ø> (ø)
git-changes-action 53.94265% <ø> (ø)
omnirpc 53.15589% <ø> (-0.07606%) ⬇️
promexporter 75.91241% <ø> (?)
rfq 28.97609% <ø> (ø)
screener-api 62.80488% <ø> (ø)
scribe 52.21130% <ø> (ø)
sin-executor 63.05419% <ø> (+1.47784%) ⬆️
stiprelayer 3.33333% <ø> (ø)
tools 21.98661% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 9218a0b and 25fa52c.
Files selected for processing (2)
  • core/metrics/README.md (1 hunks)
  • core/metrics/base.go (1 hunks)
Additional comments not posted (1)
core/metrics/base.go (1)

197-199: Ensure the new feature related to METRICS_ALWAYS_SYNC is correctly implemented.

	if core.GetEnvBool("METRICS_ALWAYS_SYNC", false) {
		extraOpts = append(extraOpts, tracesdk.WithSampler(tracesdk.AlwaysSample()))
	}

This code correctly checks the METRICS_ALWAYS_SYNC environment variable and conditionally applies the AlwaysSample() sampler if the variable is set to true. This implementation aligns with the PR objectives and follows best practices for conditional feature toggling based on environment variables.

Comment on lines 27 to 38

The metrics endpoint is exposed on `/metrics` on port `8080` by default and is compatible with prometheus. The following options control the metrics endpoint:

| Enviornment Variable | Description | Default |
|------------------------|-----------------------------------------------|------------|
| `METRICS_PORT_ENABLED` | Wether or not to enable the metrics endpoint. | `true` |
| `METRICS_PORT` | Port to serve metrics on. | `8080` |
| `METRICS_PATH` | Path to serve metrics on | `/metrics` |
| Enviornment Variable | Description | Default |
|------------------------|-----------------------------------------------------------------------------|------------|
| `METRICS_PORT_ENABLED` | Wether or not to enable the metrics endpoint. | `true` |
| `METRICS_PORT` | Port to serve metrics on. | `8080` |
| `METRICS_PATH` | Path to serve metrics on | `/metrics` |
| `METRICS_ALWAYS_SYNC` | Wether or not to wait until metrics have been exported before ending a span | `false` |

**Note: this server failing to bind to `METRICS_PORT` will not cause the application to fail to start. The error will be logged.**

Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [3-3]

Fix the typographical and grammatical issues in the introduction paragraph.

- The metrics package contains standard drivers for opentracing, profiling and metrics.You can enable this in your appplication by calling `metrics.Setup()`. This will start the metric handler defined in the `METRICS_HANDLER` environment variable. The default is `null` which is a no-op handler.
+ The metrics package contains standard drivers for opentracing, profiling, and metrics. You can enable this in your application by calling `metrics.Setup()`. This will start the metric handler defined in the `METRICS_HANDLER` environment variable. The default is `null`, which is a no-op handler.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [7-8]

Correct the spelling mistakes and typographical errors in the OTLP and Jaeger descriptions.

- | OTLP                  | [OTLP Exporter](https://opentelemetry.io/docs/specs/otel/protocol/exporter/) protocol. Supported by various external providers including [New Relic](https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-introduction/), [Signoz](https://signoz.io/blog/opentelemetry-collector-complete-guide/), [Grafana](https://grafana.com/docs/opentelemetry/collector/) and more | ✅               | ✅                    | ❌ (but it can through pyroscope, by specifying the `PYROSCOPE_ENDPOINT` enviornment variable) |
- | Jaeger                | [Jaeger](https://www.jaegertracing.io/docs/1.46/) Client Clibrary, will soon be deprecated in favor of OTLP exports to jaeger as per [this deprecation notice](https://www.jaegertracing.io/docs/1.46/client-libraries/)                                                                                                                                                                                                             | ✅               | ✅                    | ❌ (but it can through pyroscope, by specifying the `PYROSCOPE_ENDPOINT` enviornment variable) |
+ | OTLP                  | [OTLP Exporter](https://opentelemetry.io/docs/specs/otel/protocol/exporter/) protocol. Supported by various external providers including [New Relic](https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-introduction/), [Signoz](https://signoz.io/blog/opentelemetry-collector-complete-guide/), [Grafana](https://grafana.com/docs/opentelemetry/collector/) and more | ✅               | ✅                    | ❌ (but it can through pyroscope, by specifying the `PYROSCOPE_ENDPOINT` environment variable) |
+ | Jaeger                | [Jaeger](https://www.jaegertracing.io/docs/1.46/) Client Library, will soon be deprecated in favor of OTLP exports to Jaeger as per [this deprecation notice](https://www.jaegertracing.io/docs/1.46/client-libraries/)                                                                                                                                                                                                             | ✅               | ✅                    | ❌ (but it can through pyroscope, by specifying the `PYROSCOPE_ENDPOINT` environment variable) |

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [13-15]

Correct the spelling mistake in the OTLP section.

- We do our best to support enviornment variables specified in the [Otel Spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/) and have added a few of our own.
+ We do our best to support environment variables specified in the [Otel Spec](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/) and have added a few of our own.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [20-22]

Correct the spelling mistake in the Jaeger and Pyroscope sections.

- Pass in the `JAEGER_ENDPOINT` enviornment variable
- Pass in the `PYROSCOPE_ENDPOINT` environment variable
+ Pass in the `JAEGER_ENDPOINT` environment variable
+ Pass in the `PYROSCOPE_ENDPOINT` environment variable

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [41-41]

Correct the spelling mistake and improve the clarity in the Logger section.

- Currently, the entire sanguine codebase uses [ipfs go-log]("https://github.com/ipfs/go-log"). As pointed out in [#1521](https://github.com/synapsecns/sanguine/issues/1521), this is not a good long term solution since the logs are not currently appended to opentelemetry, and so new traces require telemtry.
+ Currently, the entire Sanguine codebase uses [ipfs go-log]("https://github.com/ipfs/go-log"). As pointed out in [#1521](https://github.com/synapsecns/sanguine/issues/1521), this is not a good long-term solution since the logs are not currently appended to OpenTelemetry, and so new traces require telemetry.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [43-43]

Correct the typographical and grammatical issues in the Logger section.

- In an attempt to fix this, we introduced the new context aware [otelzap logger](https://pkg.go.dev/github.com/uptrace/opentelemetry-go-extra/otelzap). Since this is in beta, you ned to call `handler.ExperimentalLogger`. In a future version, we will remove the `handler.ExperimentalLogger` and replace it with `handler.Logger` and deprecate [`ipfs/go-log`](https://github.com/ipfs/go-log).
+ In an attempt to fix this, we introduced the new context-aware [otelzap logger](https://pkg.go.dev/github.com/uptrace/opentelemetry-go-extra/otelzap). Since this is in beta, you need to call `handler.ExperimentalLogger`. In a future version, we will remove the `handler.ExperimentalLogger` and replace it with `handler.Logger` and deprecate [`ipfs/go-log`](https://github.com/ipfs/go-log).

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [51-51]

Correct the spelling and grammatical mistakes in the Limitations section.

- Currently, no enviornment variables are supported for the logger. This is a known limitation and will be fixed in a future release. Things like controlling the log level, sugarring, format, etc are [not currently supported](https://pkg.go.dev/go.uber.org/zap#NewProductionConfig). These will be added as the module beocmes more stable.
+ Currently, no environment variables are supported for the logger. This is a known limitation and will be fixed in a future release. Things like controlling the log level, sugaring, format, etc., are [not currently supported](https://pkg.go.dev/go.uber.org/zap#NewProductionConfig). These will be added as the module becomes more stable.

Comment on lines +30 to +35
| Enviornment Variable | Description | Default |
|------------------------|-----------------------------------------------------------------------------|------------|
| `METRICS_PORT_ENABLED` | Wether or not to enable the metrics endpoint. | `true` |
| `METRICS_PORT` | Port to serve metrics on. | `8080` |
| `METRICS_PATH` | Path to serve metrics on | `/metrics` |
| `METRICS_ALWAYS_SYNC` | Wether or not to wait until metrics have been exported before ending a span | `false` |
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the spelling and grammatical mistakes in the Metrics Endpoint section.

- | Enviornment Variable   | Description                                                                 | Default    |
- | `METRICS_PORT_ENABLED` | Wether or not to enable the metrics endpoint.                               | `true`     |
- | `METRICS_PORT`         | Port to serve metrics on.                                                   | `8080`     |
- | `METRICS_PATH`         | Path to serve metrics on                                                    | `/metrics` |
- | `METRICS_ALWAYS_SYNC`  | Wether or not to wait until metrics have been exported before ending a span | `false`    |
+ | Environment Variable   | Description                                                                 | Default    |
+ | `METRICS_PORT_ENABLED` | Whether or not to enable the metrics endpoint.                              | `true`     |
+ | `METRICS_PORT`         | Port to serve metrics on.                                                   | `8080`     |
+ | `METRICS_PATH`         | Path to serve metrics on.                                                   | `/metrics` |
+ | `METRICS_ALWAYS_SYNC`  | Whether or not to wait until metrics have been exported before ending a span| `false`    |

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
| Enviornment Variable | Description | Default |
|------------------------|-----------------------------------------------------------------------------|------------|
| `METRICS_PORT_ENABLED` | Wether or not to enable the metrics endpoint. | `true` |
| `METRICS_PORT` | Port to serve metrics on. | `8080` |
| `METRICS_PATH` | Path to serve metrics on | `/metrics` |
| `METRICS_ALWAYS_SYNC` | Wether or not to wait until metrics have been exported before ending a span | `false` |
| Environment Variable | Description | Default |
|------------------------|-----------------------------------------------------------------------------|------------|
| `METRICS_PORT_ENABLED` | Whether or not to enable the metrics endpoint. | `true` |
| `METRICS_PORT` | Port to serve metrics on. | `8080` |
| `METRICS_PATH` | Path to serve metrics on. | `/metrics` |
| `METRICS_ALWAYS_SYNC` | Whether or not to wait until metrics have been exported before ending a span| `false` |

@trajan0x trajan0x marked this pull request as ready for review April 3, 2024 03:04
@trajan0x trajan0x merged commit a2b8391 into master Apr 3, 2024
54 of 57 checks passed
@trajan0x trajan0x deleted the fix/metrics-sync branch April 3, 2024 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/xs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant