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

feat: add span metrics for traces #3787

Merged
merged 27 commits into from
Jul 17, 2024

Conversation

domyway
Copy link
Contributor

@domyway domyway commented Jun 21, 2024

add Histogram span_duration_milliseconds for traces, and it has "service_name", "operation_name", "status_code", "span_kind" labels .
to enable metrics, set ZO_TRACES_SPAN_METRICS_ENABLED : true
and in case operation_name will be too many to query, we can add a vrl function to convert operation_name to a cusmtom name, such as:

.o2_span_metrics_name = replace(string(.span_name)?? "/*", r'.*', "/*")
.

Summary by CodeRabbit

  • New Features

    • Introduced span metrics collection and recording to improve trace analysis.
    • Added support for OpenTelemetry metrics, including initialization and handling of meter providers.
    • Enabled configuration for span metrics with new environment variables for flexibility.
    • Introduced logging for internal errors in trace request handling.
  • Updates

    • Updated Cargo.toml to include OpenTelemetry metrics feature.
    • Publicly exposed the metrics module for broader use.
  • Bug Fixes

    • Improved error logging to aid in debugging trace issues.

Copy link

coderabbitai bot commented Jun 21, 2024

Walkthrough

The changes introduce new metrics collection capabilities using OpenTelemetry in the Rust project. This includes adding new structures and functions for tracing metrics, new configurations, and exporting mechanisms. The focus is on collecting and recording span metrics for traces, initializing and shutting down meter providers, and logging enhancements.

Changes

File Path Summary
src/job/metrics.rs Added structures and functions for tracing metrics collection using OpenTelemetry, and initialized meter provider.
src/service/traces/mod.rs Added logic for building and recording span metrics.
src/config/src/metrics.rs Added SPAN_DURATION_MILLISECONDS to track span duration metrics, updated register_metrics function.
src/config/src/config.rs Added new fields to Common struct for span metrics configuration.
src/service/exporter/mod.rs Introduced a new module for metrics exporting.
src/handler/grpc/request/traces.rs Added logging before returning an internal error in handle_trace_request function.
Cargo.toml Updated opentelemetry_sdk dependency to include "metrics" feature.
src/job/mod.rs Made metrics module public.
src/main.rs Added initialization and shutdown of a meter provider.
src/service/mod.rs Added new exporter module.
sequenceDiagram
    participant User
    participant Application
    participant TraceService
    participant MetricsProvider
    participant Exporter

    User ->> Application: Send trace data
    Application ->> TraceService: Handle trace request
    TraceService ->> MetricsProvider: Record span metrics
    MetricsProvider ->> Exporter: Export metrics
    Exporter ->> MetricsProvider: Acknowledge export
    MetricsProvider ->> TraceService: Metrics recorded
    TraceService ->> Application: Trace request handled
    Application ->> User: Response
Loading

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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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/schema.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 ☢️ Bug Something isn't working ✏️ Feature labels Jun 21, 2024
Copy link

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e7a158e and fd42be6.

Files selected for processing (3)
  • src/config/src/config.rs (1 hunks)
  • src/config/src/metrics.rs (2 hunks)
  • src/service/traces/mod.rs (4 hunks)
Additional context used
Path-based instructions (3)
src/service/traces/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/config/src/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/config/src/config.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (4)
src/service/traces/mod.rs (2)

125-125: Initialization of span_metrics is well-implemented.

This line correctly initializes span_metrics with a capacity equal to the number of resource spans, which is efficient memory management.


249-266: Implementation of span metrics recording logic.

The logic to build and push span metrics is implemented correctly. However, ensure that the removal of "o2_span_metrics_name" from v (line 256-257) does not affect other parts of the system that might expect this key to exist.

Verification successful

The search results indicate that the variable v is used later in the code, but not in a way that would be affected by the removal of the "o2_span_metrics_name" key. Specifically, v is used as part of a match arm at line 267, and it is not directly referenced in any subsequent logic that would require the "o2_span_metrics_name" key.

Based on this analysis, the removal of the "o2_span_metrics_name" key from v does not seem to impact other parts of the system.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if 'o2_span_metrics_name' is used elsewhere in the system.

# Test: Search for 'o2_span_metrics_name' in the codebase. Expect: No other usage.
rg 'o2_span_metrics_name'

Length of output: 115



Script:

#!/bin/bash
# Description: Check if `v` is used after the removal of "o2_span_metrics_name".

# Test: Search for usage of `v` after line 257 in the file src/service/traces/mod.rs.
rg 'v' -n -A 20 src/service/traces/mod.rs | awk '$1 > 257'

Length of output: 13573

src/config/src/metrics.rs (2)

567-586: Definition of the SPAN_DURATION_MILLISECONDS metric.

The metric is defined with appropriate buckets and labels that align with the PR objectives. The labels include all necessary dimensions to provide detailed insights into span metrics.


736-737: Registration of the SPAN_DURATION_MILLISECONDS metric.

The registration of the new metric is correctly implemented. This ensures that the metric is available for recording in the monitoring system.

src/config/src/config.rs Show resolved Hide resolved
src/service/traces/mod.rs Show resolved Hide resolved
src/service/traces/mod.rs Outdated Show resolved Hide resolved
Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd42be6 and b25179c.

Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • src/job/metrics.rs (2 hunks)
  • src/job/mod.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/service/traces/mod.rs (4 hunks)
Files skipped from review due to trivial changes (1)
  • Cargo.toml
Files skipped from review as they are similar to previous changes (1)
  • src/service/traces/mod.rs
Additional context used
Path-based instructions (3)
src/job/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/main.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (8)
src/job/mod.rs (1)

35-35: Public Access Granted to metrics Module

Making the metrics module public allows broader access to the new metrics functionalities. Ensure that this change aligns with the intended access control and architecture of the project.

src/job/metrics.rs (5)

49-58: Introduction of TraceMetricsItem Struct

The newly introduced TraceMetricsItem struct is well-defined with appropriate field types. Ensure all fields are necessary and consider adding documentation comments to explain each field's role in trace metrics.


60-63: Type Alias for TraceMetricsChan

The type alias for TraceMetricsChan uses Rust's async primitives effectively. This setup is appropriate for handling asynchronous message passing in metrics collection.


65-68: Initialization of TRACE_METRICS_CHAN

The static variable TRACE_METRICS_CHAN is initialized correctly using Lazy::new. This ensures thread safety and lazy initialization which is suitable for performance-sensitive applications.


288-329: Initialization of Meter Provider

The function init_meter_provider is well-structured and uses OpenTelemetry's OTLP configuration effectively. The use of metadata and credentials is secure, but ensure that sensitive information like credentials is handled securely throughout the system.


331-347: Trace Metrics Collection Functionality

The function traces_metrics_collect is designed to handle trace metrics asynchronously. The use of TRACE_METRICS_SPAN_HISTOGRAM for recording metrics is appropriate. Ensure that error handling is robust, especially in production environments.

src/main.rs (2)

207-209: Meter Provider Initialization

The initialization of the meter provider in the main function is correctly implemented. This setup is crucial for enabling the newly added metrics functionalities.


240-242: Meter Provider Shutdown

Properly shutting down the meter provider is essential for releasing resources. The implementation here ensures that resources are cleaned up, which is good practice.

src/job/metrics.rs Outdated Show resolved Hide resolved
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b25179c and ba43e60.

Files selected for processing (2)
  • src/job/metrics.rs (2 hunks)
  • src/service/traces/mod.rs (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/job/metrics.rs
  • src/service/traces/mod.rs

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=ba43e60

Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba43e60 and f6401c4.

Files selected for processing (3)
  • src/config/src/metrics.rs (3 hunks)
  • src/job/metrics.rs (2 hunks)
  • src/service/traces/mod.rs (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/config/src/metrics.rs
  • src/service/traces/mod.rs
Additional context used
Path-based instructions (1)
src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (7)
src/job/metrics.rs (7)

52-61: Struct definition for TraceMetricsItem is well-defined.

This struct is crucial for handling trace metrics data. It's well-structured to include all necessary fields for the metrics.


63-66: Type alias for TraceMetricsChan is correctly defined.

The use of a tuple for the sender and receiver wrapped in a RwLock is appropriate for thread-safe asynchronous message passing.


68-71: Initialization of TRACE_METRICS_CHAN using Lazy.

The use of Lazy for initializing the TRACE_METRICS_CHAN is appropriate to ensure it's thread-safe and only initialized once.


73-80: Histogram initialization in TRACE_METRICS_SPAN_HISTOGRAM.

The histogram is correctly initialized with appropriate units and description. This aligns with the previous comment about ensuring the unit matches the variable name.


294-336: Initialization of the OpenTelemetry meter provider is robust.

The configuration for the exporter and meter provider is detailed and appropriately set up with error handling and metadata management. This setup is crucial for ensuring accurate metrics reporting.


338-356: Metrics collection logic in traces_metrics_collect.

The function correctly handles the asynchronous receipt of metrics data and records it using the histogram. This is a key part of the metrics pipeline.


16-46: Ensure consistent use of imports and namespaces.

Imports from opentelemetry and related crates are expanded, which is good for clarity. However, ensure that all necessary imports are included, especially given the extensive use of metrics and async functionalities.

Verification successful

Ensure consistent use of imports and namespaces.

The imports in src/job/metrics.rs appear to cover a wide range of necessary functionalities, including metrics, async operations, and other utilities. Here are the key points:

  • Imports from opentelemetry, opentelemetry_otlp, and opentelemetry_sdk cover metrics and tracing functionalities.
  • Imports from tokio cover async functionalities.
  • Other imports (std, config, hashbrown, infra, once_cell, tonic) provide necessary utilities and configurations.

Based on the provided context, all necessary imports seem to be included. However, ensure to double-check the functions and types used in the file to confirm that no imports are missing.

No further action required.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Ensure all necessary imports for metrics and async functionalities are included.
rg --type rust 'use' src/job/metrics.rs

Length of output: 719

src/job/metrics.rs Outdated Show resolved Hide resolved
Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f6401c4 and e707d3b.

Files selected for processing (1)
  • src/job/metrics.rs (2 hunks)
Additional context used
Path-based instructions (1)
src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (6)
src/job/metrics.rs (6)

16-22: Consider optimizing imports.

There seems to be a redundancy in the use statements for the metrics module. This could be streamlined for better clarity and reduced verbosity.
[REFACTOR_Suggestion]

- use config::{cluster, get_config, meta::{cluster::Role, stream::StreamType}, metrics};
- use config::metrics::{NAMESPACE, SPAN_METRICS_BUCKET};
+ use config::{cluster, get_config, meta::{cluster::Role, stream::StreamType}, metrics::{self, NAMESPACE, SPAN_METRICS_BUCKET}};

52-61: New struct TraceMetricsItem looks good.

The struct TraceMetricsItem is well-defined with appropriate field types. Good job on keeping the fields public for easy access where necessary.


68-71: Initialization of TRACE_METRICS_CHAN is correct.

The use of Lazy for the static variable TRACE_METRICS_CHAN ensures thread-safe initialization. The channel size of 2048 seems reasonable, but consider documenting why this specific size was chosen.


73-80: Histogram setup in TRACE_METRICS_SPAN_HISTOGRAM.

The setup of the histogram for span duration metrics is correctly implemented. The unit of measurement and description are accurately set.


340-355: Metrics collection logic in traces_metrics_collect.

The logic to collect metrics and record them using the histogram instrument is implemented correctly. The use of key-value pairs for labeling the histogram is a good practice.


295-338: Initialization of the meter provider in init_meter_provider.

The configuration for the meter provider is correctly set with appropriate metadata, exporter settings, and interval. However, ensure that the endpoint and token are not hardcoded in production environments.

Copy link

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e707d3b and 8d3497f.

Files selected for processing (2)
  • src/config/src/config.rs (1 hunks)
  • src/job/metrics.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs
Additional context used
Path-based instructions (1)
src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (4)
src/job/metrics.rs (4)

16-16: Review imports for unused elements.

It seems like there are multiple imports under the metrics namespace. Ensure that all imported elements are actually used to prevent clutter.

Also applies to: 22-22


53-61: Ensure proper documentation for TraceMetricsItem.

The struct TraceMetricsItem is central to the metrics functionality but lacks documentation. Consider adding comments to explain the role of each field, especially how they interact with the metrics system.


68-71: Initialization of TRACE_METRICS_CHAN is thread-safe and efficient.

Using Lazy::new ensures that the channel is initialized in a thread-safe manner, and the buffer size of 2048 seems reasonable given the context. However, consider documenting why this specific size was chosen.


73-80: Correct unit of measurement for TRACE_METRICS_SPAN_HISTOGRAM.

The unit is correctly set to milliseconds (ms). This aligns with the previous suggestion to correct the unit from microseconds (us).

src/job/metrics.rs Outdated Show resolved Hide resolved
src/job/metrics.rs Outdated Show resolved Hide resolved
Copy link

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8d3497f and 40c2493.

Files selected for processing (2)
  • src/config/src/config.rs (1 hunks)
  • src/service/traces/mod.rs (4 hunks)
Additional context used
Path-based instructions (2)
src/service/traces/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/config/src/config.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (1)
src/service/traces/mod.rs (1)

126-126: Initialization of span metrics vector is efficient.

The use of Vec::with_capacity is a good practice for performance optimization when the expected size is known.

src/config/src/config.rs Show resolved Hide resolved
src/service/traces/mod.rs Show resolved Hide resolved
src/service/traces/mod.rs Show resolved Hide resolved
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40c2493 and 1118ad9.

Files selected for processing (1)
  • src/job/metrics.rs (2 hunks)
Additional context used
Path-based instructions (1)
src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (3)
src/job/metrics.rs (3)

16-22: Review of imports and TraceMetricsItem structure.

The imports and the TraceMetricsItem struct are appropriately defined for the functionality of trace metrics collection. The struct fields align with the data needed for tracing.

Also applies to: 52-61


68-91: Initialization of static variables and error handling in the run function.

The static variables TRACE_METRICS_CHAN and TRACE_METRICS_SPAN_HISTOGRAM are initialized correctly. However, the error handling in the run function could be improved by adding retry mechanisms, as previously suggested in past comments.
The suggestions from past comments still apply here.


293-338: Initialization of the meter provider.

The meter provider is initialized with appropriate settings. However, ensure the metadata keys such as "authorization" and "organization" are correctly used and that error handling is robust, especially for potential parsing errors.

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=1118ad9

Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1118ad9 and 3d3b1d8.

Files selected for processing (4)
  • src/job/metrics.rs (2 hunks)
  • src/service/exporter/mod.rs (1 hunks)
  • src/service/exporter/otlp_o2_metrics_exporter.rs (1 hunks)
  • src/service/mod.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/service/mod.rs
Additional context used
Path-based instructions (3)
src/service/exporter/mod.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/service/exporter/otlp_o2_metrics_exporter.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (10)
src/service/exporter/mod.rs (1)

1-1: Module Addition Approved

Adding the otlp_o2_metrics_exporter module aligns with the PR's objectives to enhance metrics exporting capabilities.

src/service/exporter/otlp_o2_metrics_exporter.rs (5)

16-21: New Trait Definition: MetricsClient

The MetricsClient trait is well-defined with appropriate async signatures and debug constraints. This is crucial for integration with the metrics exporting functionality.


23-28: Structure Definition: O2MetricsExporter

The O2MetricsExporter struct is appropriately defined with necessary components for metrics exporting. Ensure the components like temporality_selector and aggregation_selector are properly initialized and used.


48-62: Implementation of PushMetricsExporter for O2MetricsExporter

This implementation is crucial for integrating the custom metrics exporter with the OpenTelemetry SDK. The use of delegation to the MetricsClient for the export method is a good design choice, promoting modularity.


64-77: Constructor for O2MetricsExporter

The constructor method new is well-implemented. It properly boxes the provided implementations, which is necessary for dynamic dispatch.


79-112: New Struct and Trait Implementation: O2MetricsClient

The O2MetricsClient struct and its implementation of MetricsClient are correctly set up. The error handling within the export method logs errors appropriately, which is crucial for debugging and monitoring.

src/job/metrics.rs (4)

51-60: New Struct Definition: TraceMetricsItem

The TraceMetricsItem struct is well-defined with fields that align with the PR's objectives to enhance trace metrics. This struct will facilitate the structured handling of trace data.


67-70: Initialization of TRACE_METRICS_CHAN

The static variable TRACE_METRICS_CHAN is initialized correctly using a Lazy pattern, ensuring thread safety and initialization on first use.


72-79: Initialization of TRACE_METRICS_SPAN_HISTOGRAM

The histogram is set up correctly to measure span durations. The use of a namespace and proper units (ms) aligns with best practices.


292-319: Initialization of Meter Provider

The setup of the meter provider and the OTLP exporter is well-implemented. The use of default selectors and proper intervals for metric export is appropriate.

src/job/metrics.rs Show resolved Hide resolved
@hengfeiyang
Copy link
Contributor

/ok-to-test sha=3d3b1d8

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=52b5c41

Copy link

@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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3d3b1d8 and 52b5c41.

Files selected for processing (2)
  • src/config/src/config.rs (1 hunks)
  • src/job/metrics.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs
Additional context used
Path-based instructions (1)
src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (3)
src/job/metrics.rs (3)

16-22: Ensure necessary imports for tracing and metrics.

The imports appear appropriate for the functionalities being implemented, especially with the use of OpenTelemetry and Tokio. Ensure that all these modules are used effectively throughout the file to avoid any unused imports.


51-60: Review of TraceMetricsItem structure.

The structure is well-defined with appropriate data types for handling trace metrics. Ensure that all fields are necessary and used within the metrics collection logic.


67-80: Initialization of TRACE_METRICS_SPAN_HISTOGRAM.

The histogram is initialized with the correct unit of measurement and description, aligning with the metric's purpose. Ensure that the histogram setup follows the best practices of OpenTelemetry and matches the expected metric granularity.

Comment on lines 322 to 340
async fn traces_metrics_collect() -> Result<(), anyhow::Error> {
let mut receiver = TRACE_METRICS_CHAN.1.write().await;

while let Some(item) = receiver.recv().await {
// Record measurements using the histogram instrument.
TRACE_METRICS_SPAN_HISTOGRAM.record(
item.duration,
&[
KeyValue::new("organization", item.organization),
KeyValue::new("traces_stream_name", item.traces_stream_name),
KeyValue::new("service_name", item.service_name),
KeyValue::new("operation_name", item.span_name),
KeyValue::new("status_code", item.span_status),
KeyValue::new("span_kind", item.span_kind),
],
);
}

Ok(())
Copy link

Choose a reason for hiding this comment

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

Optimize the traces_metrics_collect function.

The function efficiently collects and records metrics. Consider adding error handling for cases where recv might fail, such as when the channel is closed, to ensure robustness.

+    if receiver.is_closed() {
+        return Err(anyhow::Error::new(std::io::Error::new(std::io::ErrorKind::BrokenPipe, "Channel closed")));
+    }
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async fn traces_metrics_collect() -> Result<(), anyhow::Error> {
let mut receiver = TRACE_METRICS_CHAN.1.write().await;
while let Some(item) = receiver.recv().await {
// Record measurements using the histogram instrument.
TRACE_METRICS_SPAN_HISTOGRAM.record(
item.duration,
&[
KeyValue::new("organization", item.organization),
KeyValue::new("traces_stream_name", item.traces_stream_name),
KeyValue::new("service_name", item.service_name),
KeyValue::new("operation_name", item.span_name),
KeyValue::new("status_code", item.span_status),
KeyValue::new("span_kind", item.span_kind),
],
);
}
Ok(())
async fn traces_metrics_collect() -> Result<(), anyhow::Error> {
let mut receiver = TRACE_METRICS_CHAN.1.write().await;
if receiver.is_closed() {
return Err(anyhow::Error::new(std::io::Error::new(std::io::ErrorKind::BrokenPipe, "Channel closed")));
}
while let Some(item) = receiver.recv().await {
// Record measurements using the histogram instrument.
TRACE_METRICS_SPAN_HISTOGRAM.record(
item.duration,
&[
KeyValue::new("organization", item.organization),
KeyValue::new("traces_stream_name", item.traces_stream_name),
KeyValue::new("service_name", item.service_name),
KeyValue::new("operation_name", item.span_name),
KeyValue::new("status_code", item.span_status),
KeyValue::new("span_kind", item.span_kind),
],
);
}
Ok(())
}

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 13d08c8 and 3d708ef.

Files selected for processing (1)
  • src/config/src/config.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=297f6c3

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3d708ef and 297f6c3.

Files selected for processing (1)
  • src/config/src/config.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 297f6c3 and d0fb809.

Files selected for processing (1)
  • src/config/src/config.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=624ec32

Copy link

@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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d0fb809 and 624ec32.

Files selected for processing (2)
  • src/job/metrics.rs (2 hunks)
  • src/service/traces/mod.rs (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/service/traces/mod.rs
Additional context used
Path-based instructions (1)
src/job/metrics.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (4)
src/job/metrics.rs (4)

74-81: Verify the unit of measurement for TRACE_METRICS_SPAN_HISTOGRAM.

Ensure that the unit "ms" aligns with the actual measurements being recorded.


51-61: LGTM!

The struct TraceMetricsItem is well-defined and covers all necessary fields for trace metrics.


68-72: Verify the buffer size for TRACE_METRICS_CHAN.

Ensure that the buffer size from the configuration is appropriate for the expected load.


294-320: Fix the typo in the metadata insertion.

There is a typo in the metadata insertion. "organizatlianion" should be "organization".

-    metadata.insert("organizatlianion", "default".parse().unwrap());
+    metadata.insert("organization", "default".parse().unwrap());

Likely invalid or redundant comment.

src/job/metrics.rs Outdated Show resolved Hide resolved
src/job/metrics.rs Show resolved Hide resolved
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 624ec32 and c68be91.

Files selected for processing (1)
  • src/handler/grpc/request/traces.rs (1 hunks)
Additional context used
Path-based instructions (1)
src/handler/grpc/request/traces.rs (1)

Pattern **/*.rs: You are a smart rustlang pull request reviewer.
You are going to review all the rustlang files.
Be concise, and add a brief explanation to your suggestions

Make sure the responses are not too verbose and keep the suggestions to the point i.e. actionable.

Additional comments not posted (1)
src/handler/grpc/request/traces.rs (1)

66-68: Confirm the error logging and handling.

The error is correctly logged before returning the internal status. Ensure that the log level error is appropriate for this context.

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=c68be91

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c68be91 and 159dbec.

Files selected for processing (7)
  • Cargo.toml (1 hunks)
  • src/config/src/config.rs (1 hunks)
  • src/config/src/metrics.rs (3 hunks)
  • src/job/mod.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/service/mod.rs (1 hunks)
  • src/service/traces/mod.rs (4 hunks)
Files skipped from review due to trivial changes (1)
  • src/service/mod.rs
Files skipped from review as they are similar to previous changes (6)
  • Cargo.toml
  • src/config/src/config.rs
  • src/config/src/metrics.rs
  • src/job/mod.rs
  • src/main.rs
  • src/service/traces/mod.rs

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=a3928df

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 159dbec and a3928df.

Files selected for processing (1)
  • src/config/src/config.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs

@hengfeiyang
Copy link
Contributor

/ok-to-test sha=e007134

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a3928df and e007134.

Files selected for processing (6)
  • Cargo.toml (1 hunks)
  • src/config/src/config.rs (1 hunks)
  • src/job/metrics.rs (2 hunks)
  • src/job/mod.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/service/traces/mod.rs (4 hunks)
Files skipped from review as they are similar to previous changes (5)
  • src/config/src/config.rs
  • src/job/metrics.rs
  • src/job/mod.rs
  • src/main.rs
  • src/service/traces/mod.rs
Additional comments not posted (1)
Cargo.toml (1)

106-106: Approved addition of the "metrics" feature to opentelemetry_sdk.

The change aligns with the PR's objectives to enhance metric collection. Ensure that this new feature integrates well with existing functionalities and does not introduce any regressions.

@hengfeiyang hengfeiyang changed the title feat: add spanmetrics for traces feat: add span metrics for traces Jul 16, 2024
Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e007134 and 6247dd6.

Files selected for processing (1)
  • src/job/metrics.rs (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/job/metrics.rs

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6247dd6 and d15e030.

Files selected for processing (1)
  • src/config/src/config.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/config/src/config.rs

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d15e030 and 95a5944.

Files selected for processing (2)
  • src/config/src/config.rs (1 hunks)
  • src/config/src/metrics.rs (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/config/src/config.rs
  • src/config/src/metrics.rs

@hengfeiyang hengfeiyang merged commit 6a5291f into openobserve:main Jul 17, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working ✏️ Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants