-
Notifications
You must be signed in to change notification settings - Fork 283
Move Resource to SDK #86
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright 2019 OpenTelemetry Authors | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| module OpenTelemetry | ||
| module SDK | ||
| module Resources | ||
| # Resource represents a resource, which captures identifying information about the entities | ||
| # for which telemetry (metrics or traces) is reported. | ||
| class Resource | ||
| class << self | ||
| private :new # rubocop:disable Style/AccessModifierDeclarations | ||
|
|
||
| # Returns a newly created {Resource} with the specified labels | ||
| # | ||
| # @param [Hash<String, String>] labels Hash of key-value pairs to be used | ||
| # as labels for this resource | ||
| # @raise [ArgumentError] If label keys and values are not strings | ||
| # @return [Resource] | ||
| def create(labels = {}) | ||
| frozen_labels = labels.each_with_object({}) do |(k, v), memo| | ||
| raise ArgumentError, 'label keys and values must be strings' unless k.is_a?(String) && v.is_a?(String) | ||
|
|
||
| memo[-k] = -v | ||
| end.freeze | ||
|
|
||
| new(frozen_labels) | ||
| end | ||
| end | ||
|
|
||
| # @api private | ||
| # The constructor is private and only for use internally by the class. | ||
| # Users should use the {create} factory method to obtain a {Resource} | ||
| # instance. | ||
| # | ||
| # @param [Hash<String, String>] frozen_labels Frozen-hash of frozen-string | ||
| # key-value pairs to be used as labels for this resource | ||
| # @return [Resource] | ||
| def initialize(frozen_labels) | ||
| @labels = frozen_labels | ||
| end | ||
|
|
||
| # Returns an enumerator for labels of this {Resource} | ||
| # | ||
| # @return [Enumerator] | ||
| def label_enumerator | ||
| @label_enumerator ||= labels.to_enum | ||
| end | ||
|
|
||
| # Returns a new, merged {Resource} by merging the current {Resource} with | ||
| # the other {Resource}. In case of a collision, the current {Resource} | ||
| # takes precedence | ||
| # | ||
| # @param [Resource] other The other resource to merge | ||
| # @return [Resource] A new resource formed by merging the current resource | ||
| # with other | ||
| def merge(other) | ||
| raise ArgumentError unless other.is_a?(Resource) | ||
|
|
||
| merged_labels = labels.merge(other.labels) do |_, old_v, new_v| | ||
| old_v.empty? ? new_v : old_v | ||
| end | ||
|
|
||
| self.class.send(:new, merged_labels.freeze) | ||
| end | ||
|
|
||
| protected | ||
|
|
||
| attr_reader :labels | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the java SDK the resource is
final: https://github.com/open-telemetry/opentelemetry-java/blob/master/sdk/src/main/java/io/opentelemetry/sdk/trace/TracerSdk.java#L50 and assigned as an EnvVarResource, which we don't yet have. We could consider doing the same and turn this into a reader.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't sure how we wanted to configure the Resource. Go has
WithServiceandWithResourcefactory methods for theTracer, but they're not wired up to anything yet. I'd like to tackle configuration of the Resource in a subsequent PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WithResource/WithService should be moved on the TracerSDK. Only Component will be available in the API based on the OTEP-007 (better than 0007)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogdandrutu this PR moves the
Resourceto the SDK, but I didn't see anything in the OTEP-007 indicating how the Resource should be configured. Is the plan to only support configuration from environment variables, as in the Java SDK, or should we also allow explicit manual configuration like the Go SDK?