refactor: moved telemetry environment from constants and code to environment variables
This commit is contained in:
parent
b8ab58f43c
commit
2a88807b01
|
@ -16,37 +16,29 @@ const templateString = `// Code generated by go generate. DO NOT EDIT.
|
|||
package {{ .Package }}
|
||||
|
||||
const (
|
||||
{{ .Constants.Environment }} = "{{ .Environment }}"
|
||||
{{ .Constants.Module }} = "{{ .Module }}"
|
||||
{{ .Constants.Version }} = "{{ .Version }}"
|
||||
{{ .Constants.Name }} = "{{ .Name }}"
|
||||
{{ .Constants.Namespace }} = "{{ .Namespace }}"
|
||||
{{ .Constants.Module }} = "{{ .Module }}"
|
||||
{{ .Constants.Version }} = "{{ .Version }}"
|
||||
{{ .Constants.Name }} = "{{ .Name }}"
|
||||
{{ .Constants.Namespace }} = "{{ .Namespace }}"
|
||||
)`
|
||||
|
||||
type templateData struct {
|
||||
Environment string
|
||||
Module string
|
||||
Name string
|
||||
Namespace string
|
||||
Package string
|
||||
Version string
|
||||
Constants constantNames
|
||||
Module string
|
||||
Name string
|
||||
Namespace string
|
||||
Package string
|
||||
Version string
|
||||
Constants constantNames
|
||||
}
|
||||
|
||||
type constantNames struct {
|
||||
Environment string
|
||||
Module string
|
||||
Name string
|
||||
Namespace string
|
||||
Version string
|
||||
Module string
|
||||
Name string
|
||||
Namespace string
|
||||
Version string
|
||||
}
|
||||
|
||||
func main() {
|
||||
constEnvironment := flag.String(
|
||||
"const-environment",
|
||||
"ENVIRONMENT",
|
||||
"environment constant name",
|
||||
)
|
||||
constModule := flag.String(
|
||||
"const-module",
|
||||
"MODULE",
|
||||
|
@ -68,11 +60,6 @@ func main() {
|
|||
"version constant name",
|
||||
)
|
||||
|
||||
environment := flag.String(
|
||||
"environment",
|
||||
"development",
|
||||
"target environment of the build",
|
||||
)
|
||||
modFile := flag.String(
|
||||
"mod",
|
||||
"go.mod",
|
||||
|
@ -122,18 +109,16 @@ func main() {
|
|||
|
||||
var buf bytes.Buffer
|
||||
err = constantsTemplate.Execute(&buf, templateData{
|
||||
Environment: *environment,
|
||||
Module: mod.Module.Mod.Path,
|
||||
Name: *name,
|
||||
Namespace: *namespace,
|
||||
Package: *packageName,
|
||||
Version: *version,
|
||||
Module: mod.Module.Mod.Path,
|
||||
Name: *name,
|
||||
Namespace: *namespace,
|
||||
Package: *packageName,
|
||||
Version: *version,
|
||||
Constants: constantNames{
|
||||
Environment: *constEnvironment,
|
||||
Module: *constModule,
|
||||
Name: *constName,
|
||||
Namespace: *constNamespace,
|
||||
Version: *constVersion,
|
||||
Module: *constModule,
|
||||
Name: *constName,
|
||||
Namespace: *constNamespace,
|
||||
Version: *constVersion,
|
||||
},
|
||||
})
|
||||
assert(err)
|
||||
|
|
1
fly.toml
1
fly.toml
|
@ -11,6 +11,7 @@ ANILIST_GRAPHQL_ENDPOINT = "https://graphql.anilist.co"
|
|||
DATA_PATH = "/var/handler"
|
||||
OTEL_EXPORTER_OTLP_PROTOCOL = "http/protobuf"
|
||||
OTEL_EXPORTER_OTLP_ENDPOINT = "https://otlp-gateway-prod-eu-west-0.grafana.net/otlp"
|
||||
OTEL_RESOURCE_ATTRIBUTES = "deployment.environment=production"
|
||||
|
||||
[build.args]
|
||||
VERSION = "0.1.0-rc.1"
|
||||
|
|
|
@ -3,9 +3,8 @@
|
|||
package telemetry
|
||||
|
||||
const (
|
||||
ENVIRONMENT = "development"
|
||||
MODULE = "github.com/wwmoraes/anilistarr"
|
||||
VERSION = "0.1.0-rc.1"
|
||||
NAME = "anilistarr"
|
||||
NAMESPACE = "api"
|
||||
VERSION = "0.1.0-rc.1"
|
||||
)
|
||||
|
|
|
@ -51,11 +51,10 @@ func init() {
|
|||
var err error
|
||||
otlpResource, err = resource.Merge(resource.Empty(), resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
semconv.ServiceNamespace(NAMESPACE),
|
||||
semconv.ServiceName(NAME),
|
||||
semconv.ServiceVersion(VERSION),
|
||||
semconv.CodeNamespace(MODULE),
|
||||
semconv.DeploymentEnvironment(ENVIRONMENT),
|
||||
semconv.ServiceName(NAME),
|
||||
semconv.ServiceNamespace(NAMESPACE),
|
||||
semconv.ServiceVersion(VERSION),
|
||||
))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to create OTLP resource: %s", err.Error())
|
||||
|
|
Loading…
Reference in a new issue