Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

If the invocation interval between trace.StartSpan and span.End() is too small,I can't find my service registered in jaeger on Jaeger UI #21

Open
XianLeiGirl opened this issue Dec 8, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@XianLeiGirl
Copy link

XianLeiGirl commented Dec 8, 2021

problem

my code is come from quickstart
I replace openzipkin with jaeger:

package main

import (
	"bytes"
	"context"
	"encoding/binary"
	"fmt"
	"log"
	"time"

	"contrib.go.opencensus.io/exporter/jaeger"
	"go.opencensus.io/trace"
)

func main() {
	//// 1. Configure exporter to export traces to Zipkin.
	//localEndpoint, err := openzipkin.NewEndpoint("go-quickstart", "192.168.1.5:5454")
	//if err != nil {
	//	log.Fatalf("Failed to create the local zipkinEndpoint: %v", err)
	//}
	//reporter := zipkinHTTP.NewReporter("http://localhost:9411/api/v2/spans")
	//ze := zipkin.NewExporter(reporter, localEndpoint)
	//trace.RegisterExporter(ze)
	//
	//// 2. Configure 100% sample rate, otherwise, few traces will be sampled.
	//trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()})

	agentEndpointURI := "http://localhost:6831"
	collectorEndpointURI := "http://localhost/api/traces"

	je, err := jaeger.NewExporter(jaeger.Options{
		AgentEndpoint:     agentEndpointURI,
		CollectorEndpoint: collectorEndpointURI,
		ServiceName:       "demo",
	})
	if err != nil {
		log.Fatalf("Failed to create the Jaeger exporter: %v", err)
	}

	// 3. Create a span with the background context, making this the parent span.
	// A span must be closed.
	ctx, span := trace.StartSpan(context.Background(), "main")
	// 5b. Make the span close at the end of this function.
	defer span.End()

	for i := 0; i < 10; i++ {
		doWork(ctx)
	}
}

func doWork(ctx context.Context) {
	// 4. Start a child span. This will be a child span because we've passed
	// the parent span's ctx.
	_, span := trace.StartSpan(ctx, "doWork")
	// 5a. Make the span close at the end of this function.
	defer span.End()

	fmt.Println("doing busy work")
	time.Sleep(80 * time.Millisecond)
	buf := bytes.NewBuffer([]byte{0xFF, 0x00, 0x00, 0x00})
	num, err := binary.ReadVarint(buf)
	if err != nil {
		// 6. Set status upon error
		span.SetStatus(trace.Status{
			Code:    trace.StatusCodeUnknown,
			Message: err.Error(),
		})
	}

	// 7. Annotate our span to capture metadata about our operation
	span.Annotate([]trace.Attribute{
		trace.Int64Attribute("bytes to int", num),
	}, "Invoking doWork")
	time.Sleep(20 * time.Millisecond)
}

when I run my program and access port 16686 of the Jaeger UI,I can't find my service registered in jaeger on the Jaeger UI

solution

just replace "time.Sleep(20 * time.Millisecond)" with "time.Sleep(time.Second)"

why is that?

@XianLeiGirl XianLeiGirl added the bug Something isn't working label Dec 8, 2021
@XianLeiGirl XianLeiGirl changed the title If the interval between trace.StartSpan and sapn.End() is too small,I can't find my service registered in jaeger on Jaeger UI If the invocation interval between trace.StartSpan and span.End() is too small,I can't find my service registered in jaeger on Jaeger UI Dec 8, 2021
@iideas18
Copy link

iideas18 commented Dec 8, 2021

Hi, you Install these tools without encountering issues19???

@XianLeiGirl
Copy link
Author

no,I install jaeger with command: "docker run -d --name jaeger -p 6831:6831/udp -p 16686:16686 -p 14268:14268 jaegertracing/all-in-one:1.16"

@iideas18
Copy link

iideas18 commented Dec 9, 2021

how can you import this mod, if you did not install "contrib.go.opencensus.io/exporter/jaeger" in your code?

@XianLeiGirl
Copy link
Author

maybe I understand that I go get "contrib.go.opencensus.io/exporter/jaeger" to import this to my mod?

@iideas18
Copy link

iideas18 commented Dec 9, 2021

I think so.

@XianLeiGirl
Copy link
Author

But that's what I'm doing now, I still don't understand why my problem happened.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants