You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
9 months ago
|
package flydetector
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"os"
|
||
|
|
||
|
"go.opentelemetry.io/otel/attribute"
|
||
|
"go.opentelemetry.io/otel/sdk/resource"
|
||
|
semconv "go.opentelemetry.io/otel/semconv/v1.24.0"
|
||
|
)
|
||
|
|
||
|
var _ resource.Detector = &FlyDetector{}
|
||
|
|
||
|
type FlyDetector struct{}
|
||
|
|
||
|
func NewDetector() resource.Detector {
|
||
|
return &FlyDetector{}
|
||
|
}
|
||
|
|
||
|
func (d *FlyDetector) Detect(_ context.Context) (*resource.Resource, error) {
|
||
|
a := []attribute.KeyValue{semconv.CloudProviderKey.String("fly")}
|
||
|
|
||
|
if an, ok := os.LookupEnv("FLY_APP_NAME"); ok {
|
||
|
a = append(a, attribute.String("fly.app_name", an))
|
||
|
} else {
|
||
|
return resource.Empty(), nil
|
||
|
}
|
||
|
|
||
|
if mid, ok := os.LookupEnv("FLY_MACHINE_ID"); ok {
|
||
|
a = append(a, attribute.String("fly.machine_id", mid))
|
||
|
}
|
||
|
|
||
|
if aid, ok := os.LookupEnv("FLY_ALLOC_ID"); ok {
|
||
|
a = append(a, attribute.String("fly.alloc_id", aid))
|
||
|
}
|
||
|
|
||
|
if pg, ok := os.LookupEnv("FLY_PROCESS_GROUP"); ok {
|
||
|
a = append(a, attribute.String("fly.process_group", pg))
|
||
|
}
|
||
|
|
||
|
if mv, ok := os.LookupEnv("FLY_MACHINE_VERSION"); ok {
|
||
|
a = append(a, attribute.String("fly.machine_version", mv), semconv.CloudResourceID(mv))
|
||
|
}
|
||
|
|
||
|
if reg, ok := os.LookupEnv("FLY_REGION"); ok {
|
||
|
a = append(a, attribute.String("fly.region", reg), semconv.CloudRegionKey.String(reg))
|
||
|
}
|
||
|
|
||
|
if ir, ok := os.LookupEnv("FLY_IMAGE_REF"); ok {
|
||
|
a = append(a, attribute.String("fly.image_ref", ir))
|
||
|
}
|
||
|
|
||
|
return resource.NewWithAttributes(semconv.SchemaURL, a...), nil
|
||
|
}
|