forked from jaegertracing/jaeger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
96 lines (81 loc) · 2.88 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"go.uber.org/zap"
"github.com/zdyj3170101136/jaeger/cmd/anonymizer/app"
"github.com/zdyj3170101136/jaeger/cmd/anonymizer/app/anonymizer"
"github.com/zdyj3170101136/jaeger/cmd/anonymizer/app/query"
"github.com/zdyj3170101136/jaeger/cmd/anonymizer/app/uiconv"
"github.com/zdyj3170101136/jaeger/cmd/anonymizer/app/writer"
"github.com/zdyj3170101136/jaeger/pkg/version"
)
var logger, _ = zap.NewDevelopment()
func main() {
options := app.Options{}
command := &cobra.Command{
Use: "jaeger-anonymizer",
Short: "Jaeger anonymizer hashes fields of a trace for easy sharing",
Long: `Jaeger anonymizer queries Jaeger query for a trace, anonymizes fields, and store in file`,
Run: func(cmd *cobra.Command, args []string) {
prefix := options.OutputDir + "/" + options.TraceID
conf := writer.Config{
MaxSpansCount: options.MaxSpansCount,
CapturedFile: prefix + ".original.json",
AnonymizedFile: prefix + ".anonymized.json",
MappingFile: prefix + ".mapping.json",
AnonymizerOpts: anonymizer.Options{
HashStandardTags: options.HashStandardTags,
HashCustomTags: options.HashCustomTags,
HashLogs: options.HashLogs,
HashProcess: options.HashProcess,
},
}
writer, err := writer.New(conf, logger)
if err != nil {
logger.Fatal("error while creating writer object", zap.Error(err))
}
query, err := query.New(options.QueryGRPCHostPort)
if err != nil {
logger.Fatal("error while creating query object", zap.Error(err))
}
spans, err := query.QueryTrace(options.TraceID)
if err != nil {
logger.Fatal("error while querying for trace", zap.Error(err))
}
for _, span := range spans {
writer.WriteSpan(&span)
}
writer.Close()
uiCfg := uiconv.Config{
CapturedFile: conf.AnonymizedFile,
UIFile: prefix + ".anonymized-ui-trace.json",
TraceID: options.TraceID,
}
if err := uiconv.Extract(uiCfg, logger); err != nil {
logger.Fatal("error while extracing UI trace", zap.Error(err))
}
logger.Sugar().Infof("Wrote UI-compatible anonymized file to %s", uiCfg.UIFile)
},
}
options.AddFlags(command)
command.AddCommand(version.Command())
if err := command.Execute(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}