-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
68 lines (47 loc) · 1.35 KB
/
logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"errors"
"github.com/rs/zerolog/log"
"github.com/snapdocs/go-common/logging"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
func testDatadogAndAirbrakes() {
log.Logger = log.Logger.With().Str("service", "nickbehrens-go-playground-v0.0.0").Logger()
tracer.Start(
tracer.WithEnv("dev"),
tracer.WithService("nickbehrens-go-playground"),
tracer.WithServiceVersion("version-0.0.1"),
)
importantGoStuff()
err := ohNoAnAirbrake()
if err != nil {
log.Fatal().Err(err).Msg("Error with airbrake function.")
}
// This line stopps the tracer and flushes out the Datadog agent.
defer tracer.Stop()
}
func importantGoStuff() {
span := tracer.StartSpan("important.go.method")
span.SetTag("I a tag", "im a value for that tag")
defer span.Finish()
log.Info().Msg("my log message to datadog")
log.Printf("my log message %v", span)
}
func ohNoAnAirbrake() error {
config := &logging.Config{
ProjectId: 306382,
ProjectKey: "720f6524fc1a5df11d246933a1eaef03",
Environment: "development",
BreakLogLevel: "info",
LogLevel: "info",
}
err := config.SetupWithZeroLog()
if err != nil {
log.Fatal().Err(err).Msg("Unable to setup with ZeroLog.")
return err
}
err = errors.New("nickbehrens-development-operation-failed")
log.Fatal().Err(err).Msg("Failed my operation.")
defer logging.Close()
return nil
}