https://signoz.io logo
#contributing
Title
# contributing
ф

Филипп Пономаренко

12/13/2022, 7:42 PM
Hi all. I get the following message when I run my program.
OTLP partial success: empty message (0 spans rejected)
Can anyone tell me why this happens and how it can be fixed, or at least make logging not to the console, but to a file?
p

Pranay

12/14/2022, 5:24 AM
hey Philip, can you share what were you trying to do and what steps you took which showed this message?
ф

Филипп Пономаренко

12/14/2022, 11:02 AM
@Pranay This is the complete code of the test program where this error occurs. As far as I understand this error occurs after I call span.End() in a loop.
Copy code
package main

import (
	"context"
	"log"
	"math/rand"
	"os"
	"strings"
	"time"

	"<http://github.com/go-redis/redis/extra/redisotel/v9|github.com/go-redis/redis/extra/redisotel/v9>"
	"<http://github.com/go-redis/redis/v9|github.com/go-redis/redis/v9>"
	"<http://github.com/joho/godotenv|github.com/joho/godotenv>"
	"<http://google.golang.org/grpc/credentials|google.golang.org/grpc/credentials>"

	"<http://go.opentelemetry.io/otel|go.opentelemetry.io/otel>"
	"<http://go.opentelemetry.io/otel/attribute|go.opentelemetry.io/otel/attribute>"
	"<http://go.opentelemetry.io/otel/exporters/otlp/otlptrace|go.opentelemetry.io/otel/exporters/otlp/otlptrace>"
	"<http://go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc|go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc>"
	"<http://go.opentelemetry.io/otel/sdk/resource|go.opentelemetry.io/otel/sdk/resource>"
	"<http://go.opentelemetry.io/otel/sdk/trace|go.opentelemetry.io/otel/sdk/trace>"
	_trace "<http://go.opentelemetry.io/otel/trace|go.opentelemetry.io/otel/trace>"
)

var ServiceName string
var collectorURL string
var insecure string

var Tracer _trace.Tracer

var rdb *redis.Client

func CreateResources(_serviceName string) (*resource.Resource, error) {

	err := godotenv.Load()
	if err != nil {
		return nil, err
	}

	ServiceName = _serviceName
	collectorURL = os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")
	insecure = os.Getenv("INSECURE_MODE")

	resources, err := resource.New(
		context.Background(),
		resource.WithAttributes(
			attribute.String("service.name", ServiceName),
			attribute.String("library.language", "go"),
		),
	)
	if err != nil {
		return nil, err
	}

	Tracer = otel.Tracer(_serviceName)

	return resources, nil
}

func RunTracer(resources *resource.Resource) (*otlptrace.Exporter, error) {

	secureOption := otlptracegrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(nil, ""))
	if len(insecure) > 0 {
		secureOption = otlptracegrpc.WithInsecure()
	}

	exporterTrace, err := otlptrace.New(
		context.Background(),
		otlptracegrpc.NewClient(
			secureOption,
			otlptracegrpc.WithEndpoint(collectorURL),
		),
	)
	if err != nil {
		return nil, err
	}

	otel.SetTracerProvider(
		trace.NewTracerProvider(
			trace.WithSampler(trace.AlwaysSample()),
			trace.WithBatcher(exporterTrace),
			trace.WithResource(resources),
		),
	)

	return exporterTrace, nil
}

func main() {
	resources, err := CreateResources("test_app")
	if err != nil {
		log.Fatal(err)
	}

	exporterTrace, err := RunTracer(resources)
	if err != nil {
		log.Fatal(err)
	}
	defer func() {
		if err := exporterTrace.Shutdown(context.Background()); err != nil {
			log.Fatalf("Error shutting down tracer provider: %v", err)
		}
	}()

	ctx := context.Background()

	runRedis()

	for {
		ctx, span := Tracer.Start(ctx, "main1")

		str := randStr()

		RedisSet(ctx, str, str)

		RedisGet(ctx, str)

		span.End()

		time.Sleep(10 * time.Second)
	}
}

func runRedis() {
	rdb = redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "",
		DB:       0,
	})

	// Enable tracing instrumentation.
	if err := redisotel.InstrumentTracing(rdb); err != nil {
		panic(err)
	}
}

func RedisSet(ctx context.Context, key string, value string) error {

	ctx, span := Tracer.Start(ctx, "redis set")
	defer span.End()

	err := rdb.Set(ctx, key, value, 0).Err()
	if err != nil {
		return err
	}

	log.Println("RedisSet ", key, value)

	return nil
}

func RedisGet(ctx context.Context, key string) (string, error) {

	ctx, span := Tracer.Start(ctx, "redis get")
	defer span.End()

	val, err := rdb.Get(ctx, key).Result()
	if err != nil {
		return "", err
	}

	log.Println("RedisGet ", val)

	return val, nil
}

func randStr() string {
	rand.Seed(time.Now().UnixNano())
	chars := []rune("ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ" +
		"abcdefghijklmnopqrstuvwxyzåäö" +
		"0123456789")
	length := 8
	var b strings.Builder
	for i := 0; i < length; i++ {
		b.WriteRune(chars[rand.Intn(len(chars))])
	}

	return b.String()
}
Hello, @Pranay. Do you have any idea how this can be solved?
p

Pranay

12/16/2022, 9:40 AM
will check and get back.
ф

Филипп Пономаренко

12/16/2022, 10:19 AM
Thank you
Hi, @Pranay. Did you figure out what could be the problem?
s

Srikanth Chekuri

12/20/2022, 7:08 AM
p

Pranay

12/22/2022, 3:16 AM
@Филипп Пономаренко 👆 Do check out and let us know if this solved the issue
3 Views