otel

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() log.Logger
Example

nolint: lll

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"time"

	"gitoa.ru/go-4devs/log/otel"
	"go.opentelemetry.io/otel/api/trace/tracetest"
)

func main() {
	start, _ := time.Parse(time.RFC3339, "2020-09-20T12:49:52+03:00")
	tp := tracetest.NewProvider()
	tracer := tp.Tracer("4devs/log")
	ctx, span := tracer.Start(context.Background(), "test")

	prov := otel.New()
	prov.ErrKV(ctx, "some message", "error", "some error message")
	prov.InfoKV(ctx, "some info message", "data info", "additional data")

	defer span.End()

	s := span.(*tracetest.Span)
	for _, e := range s.Events() {
		e.Timestamp = start
		j, _ := json.Marshal(e)
		fmt.Println(string(j))
	}

}
Output:

{"Timestamp":"2020-09-20T12:49:52+03:00","Name":"some message","Attributes":{"SeverityNumber":{"Type":"INT64","Value":17},"SeverityText":{"Type":"STRING","Value":"ERROR"},"error":{"Type":"STRING","Value":"some error message"}}}
{"Timestamp":"2020-09-20T12:49:52+03:00","Name":"some info message","Attributes":{"SeverityNumber":{"Type":"INT64","Value":9},"SeverityText":{"Type":"STRING","Value":"INFO"},"data info":{"Type":"STRING","Value":"additional data"}}}

Types

type Level

type Level int

func (Level) String

func (i Level) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL