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
Add Schema URL support to Resource #1938
Add Schema URL support to Resource #1938
Conversation
@MrAlias @Aneurysm9 Please have a look. This PR implements the Resource portion of schema URL. It imports the current semconv package. Once we agree on #1933 this will need to be changed to import a specific semconv package version. |
Codecov Report
@@ Coverage Diff @@
## main #1938 +/- ##
=====================================
Coverage 77.1% 77.2%
=====================================
Files 161 161
Lines 8554 8595 +41
=====================================
+ Hits 6602 6637 +35
- Misses 1696 1699 +3
- Partials 256 259 +3
|
e689c86
to
d896358
Compare
@MrAlias @Aneurysm9 Assuming we are OK with |
Tests are unstable and keep failing. I do not think it is related to my changes in any way (e.g. TestNewBatchSpanProcessorWithOptions failed). |
d896358
to
9fe13b2
Compare
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.
Is the end goal to require all resource be linked to a schema? If so, I'm hesitant to release a way to create a resource without one (NewSchemaless
).
I have some suggestions as to how we can make this happen, but want to make sure I understand the end goal first.
I think we can't force that yet. The schema should be optional. The SDK will create resources with the right schema out of the box, but I don't think we are ready to declare schemaless resources invalid. |
Is this something we would declare in v2? |
I am not sure, probably not. I guess there will always be the cases when people want to "just send some resource" without putting much thought into what schema it follows. |
9fe13b2
to
6782b74
Compare
Agreed. Users may put arbitrary keys/values into resources that have no relation to any defined schema and I'm not sure we should stop them. |
This implements specification requirement: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-creation - Changes `resource.NewWithAttributes` to require a schema URL. The old function is still available as `resource.NewSchemaless`. This is a breaking change. We want to encourage using schema URL and make it a conscious choice to have a resource without schema. - Merge schema URLs acccording to the spec in resource.Merge. - Several builtin resource detectors now correctly populate the schema URL.
6782b74
to
6c30e22
Compare
I will rerun for now. |
@Aneurysm9 @MrAlias can we merge or you want to have another look? |
Just an end user chiming in here when trying to upgrade my launcher from 0.20 to 1.1, and I'm not understanding what schemas and their URLs are used for? I wrote a detector and just trying to create For example, if I was doing something like: // Detect detects from the environment ENV and VERSION.
func (Environment) Detect(ctx context.Context) (*resource.Resource, error) {
a := []attribute.KeyValue{
semconv.DeploymentEnvironmentKey.String(os.Getenv("ENV")),
semconv.ServiceNameKey.String(os.Getenv("SERVICE_NAME")),
semconv.ServiceVersionKey.String(os.Getenv("SERVICE_VERSION")),
}
return resource.NewWithAttributes(a...), nil
} Am I suppose to write my own schema, or does this fit the 1.4.0 semconv schema because I'm using The entire versioning semconv and schema thing isn't very well explained anywhere (and the spec is too convoluted to understand). Maybe I'm obtuse, or OTel is not user friendly, but I'm likely going to use |
No, you don't need to write your own schema and don't need to publish it on a server. If you are using a semconv package then you are using OpenTelemetry schema. OpenTelemetry schema is already published at https://opentelemetry.io/schemas/ (e.g. https://opentelemetry.io/schemas/1.7.0). All you need to do is pass the // Detect detects from the environment ENV and VERSION.
func (Environment) Detect(ctx context.Context) (*resource.Resource, error) {
a := []attribute.KeyValue{
semconv.DeploymentEnvironmentKey.String(os.Getenv("ENV")),
semconv.ServiceNameKey.String(os.Getenv("SERVICE_NAME")),
semconv.ServiceVersionKey.String(os.Getenv("SERVICE_VERSION")),
}
return resource.NewWithAttributes(semconv.SchemaURL, a...), nil
} This correctly sets the schema URL to match the semantic conventions that you are using for the attributes. The only case that you want to create your own schema and publish it on a server is when you are NOT using OpenTelemetry's semantic conventions and are inventing your own conventions for everything. For the vast majority of users this is unnecessary and undesirable. |
I see, thanks for elaborating. |
This implements specification requirement:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/sdk.md#resource-creation
Change
resource.NewWithAttributes
to require a schema URL. The old functionis still available as
resource.NewSchemaless
. This is a breaking change.We want to encourage using schema URL and make it a conscious choice to have a
resource without schema.
resource.Merge merges schema URLs according to the spec.
Several builtin resource detectors now correctly populate the schema URL.