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

feature: detect resources from environment variables when not set in config #64

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

devnev
Copy link
Contributor

@devnev devnev commented Aug 30, 2024

Reason for This PR

OpenTelemetry has some standardised environment variables for resource attributes, which this plugin should respect.
https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration

Description of Changes

For the four resource attributes that can be defined in the config (service.name, service.version, service.instance.id, service.namespace), if the value is not set in the config, the plugin will try to take the value from the standardised otel environment variables, and only inject a default if no value is found that way.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Enhanced flexibility in service configuration with dynamic handling of service attributes.
    • Updated OpenTelemetry resource creation process for improved error handling and adaptability.
  • Bug Fixes

    • Improved error detection during resource creation to prevent unhandled issues.
  • Documentation

    • Retained deprecation warnings for service attributes to maintain backward compatibility.

Copy link

coderabbitai bot commented Aug 30, 2024

Walkthrough

The changes involve updates to the initialization processes in config.go and plugin.go. The Config structure's InitDefault method now uses a dynamic fillValue function for setting service attributes, improving flexibility. In plugin.go, the resource creation logic has been enhanced with better error handling and updated OpenTelemetry conventions, returning both resource pointers and errors to improve robustness.

Changes

Files Change Summary
config.go Updated InitDefault to use fillValue for dynamic service attribute handling. Simplified Resource initialization. Retained deprecation warnings under new conditions.
plugin.go Updated OpenTelemetry version to v1.26.0. Enhanced resource creation with error handling and a new return signature for newResource.

Sequence Diagram(s)

sequenceDiagram
    participant Config
    participant Resource
    participant Plugin

    Config->>Resource: Call InitDefault
    Resource->>Config: Use fillValue for attributes
    Plugin->>Resource: Call newResource
    Resource-->>Plugin: Return resource and error
    Plugin->>Plugin: Handle resource creation
Loading

Poem

🐇 In the meadow, changes bloom,
With attributes that now can zoom.
Configs dance, plugins sing,
Error handling, a lovely thing!
Hop along, let’s celebrate,
New beginnings, oh, how great! 🌼


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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

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

Outside diff range, codebase verification and nitpick comments (3)
config.go (1)

Line range hint 68-97: Refactor and centralization of configuration logic approved.

The use of the fillValue function centralizes and simplifies the setting of service attributes, enhancing maintainability and flexibility. However, consider adding error handling or logging for the retrieval of environment attributes to ensure robustness in cases where the environment setup might be incorrect.

The code changes are approved.

Consider adding error handling or logging for the retrieval of environment attributes.

plugin.go (2)

115-121: Improved error handling in resource initialization.

The changes to handle errors from the newResource function enhance the robustness of the initialization process. Consider adding more detailed error messages to aid in debugging when resource creation fails.

The code changes are approved.

Consider enhancing error messages for better debugging and traceability.


168-182: Enhanced resource creation with comprehensive options.

The refactoring of the newResource function to return both a resource pointer and an error significantly improves error handling capabilities. Consider passing the context from the caller to resource.New for better traceability and control over timeouts and cancellations.

The code changes are approved.

Consider using the caller's context in resource.New to enhance traceability and control.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dc7a816 and decf6b5.

Files selected for processing (2)
  • config.go (4 hunks)
  • plugin.go (3 hunks)

config.go Show resolved Hide resolved
@rustatian rustatian self-requested a review August 30, 2024 10:45
@rustatian rustatian added the enhancement New feature or request label Aug 30, 2024
config.go Show resolved Hide resolved
@rustatian rustatian changed the title Detect resources from environment variables when not set in config feature: detect resources from environment variables when not set in config Aug 30, 2024
@rustatian
Copy link
Member

Hello again @devnev 👋
Thank you for the PR 👍 Give me a few days, need to finish some urgent tasks 😃

@devnev
Copy link
Contributor Author

devnev commented Aug 30, 2024

@rustatian no rush, but I'll also be on holidays so only checking in here or there

@rustatian
Copy link
Member

Hey @devnev 👋
I apologize for such a long review, everything is good to go, thank you 👍

@rustatian rustatian merged commit 56402f0 into roadrunner-server:master Oct 26, 2024
4 checks passed
@devnev devnev deleted the standard-otel-envs branch October 28, 2024 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants