github.com/blend/go-sdk@v1.20220411.3/cmd/traces/main.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"context"
    12  	"encoding/json"
    13  	"flag"
    14  	"log"
    15  	"os"
    16  
    17  	"github.com/blend/go-sdk/datadog/traceserver"
    18  )
    19  
    20  var (
    21  	flagBindAddr = flag.String("bind-addr", bindAddr(), "The bind address for the server")
    22  )
    23  
    24  func bindAddr() string {
    25  	if value := os.Getenv("BIND_ADDR"); value != "" {
    26  		return value
    27  	}
    28  	return "127.0.0.1:0"
    29  }
    30  
    31  func main() {
    32  	flag.Parse()
    33  
    34  	logger := log.New(os.Stdout, "traces|", log.LstdFlags)
    35  
    36  	server := traceserver.Server{
    37  		Addr: *flagBindAddr,
    38  		Log:  logger,
    39  		Handler: func(_ context.Context, spans ...*traceserver.Span) {
    40  			printer := json.NewEncoder(os.Stdout)
    41  			printer.SetIndent("", "  ")
    42  			for _, span := range spans {
    43  				_ = printer.Encode(span)
    44  			}
    45  		},
    46  	}
    47  
    48  	if err := server.Start(); err != nil {
    49  		logger.Fatal(err)
    50  	}
    51  }