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

Getting Started #2552

Closed
Charlotte3240 opened this issue Jan 26, 2022 · 2 comments
Closed

Getting Started #2552

Charlotte3240 opened this issue Jan 26, 2022 · 2 comments
Milestone

Comments

@Charlotte3240
Copy link

cannot merge resource due to conflicting Schema URL


func newResource() *resource.Resource {
	r, err := resource.Merge(
		resource.Default(),
		resource.NewWithAttributes(
			"semconv.SchemaURL,",
			semconv.ServiceNameKey.String("DemoService"),
			semconv.ServiceNamespaceKey.String("dev"),
			semconv.ServiceVersionKey.String("v1.0"),
			attribute.String("key", "value"),
		))

	if err != nil {
		log.Println("create resource error:", err)
		return nil
	}
	return r
}
@dmathieu
Copy link
Member

Hi,

You're getting this error because both your resources have a schema URL provided.
See the schema URL merge logic.

This happens because you're using an invalid schemaURL (the first argument in NewWithAttributes). You should use semconv.SchemaURL, not "semconv.SchemaURL".

The following merges properly:

package main

import (
	"fmt"
	"log"
	"os"

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/sdk/resource"
	semconv "go.opentelemetry.io/otel/semconv/v1.7.0"
)

func main() {
	r := newResource()
	fmt.Fprintf(os.Stdout, "%#v", r)
}

func newResource() *resource.Resource {
	r, err := resource.Merge(
		resource.Default(),
		resource.NewWithAttributes(
			semconv.SchemaURL,
			semconv.ServiceNameKey.String("DemoService"),
			semconv.ServiceNamespaceKey.String("dev"),
			semconv.ServiceVersionKey.String("v1.0"),
			attribute.String("key", "value"),
		))

	if err != nil {
		log.Println("create resource error:", err)
		return nil
	}
	return r
}

@MrAlias
Copy link
Contributor

MrAlias commented Feb 4, 2022

This comment looks to have addressed the issue. Closing as it looks resolved, please reopen if this was in error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants