Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
This repository was 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

@XianLeiGirl

Description

@XianLeiGirl

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions