github.com/blend/go-sdk@v1.20220411.3/stats/default_tags.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stats
     9  
    10  import "github.com/blend/go-sdk/env"
    11  
    12  // AddDefaultTagsFromEnv adds default tags to a collector from environment values.
    13  func AddDefaultTagsFromEnv(collector Collector) {
    14  	if collector == nil {
    15  		return
    16  	}
    17  	collector.AddDefaultTags(
    18  		Tag(TagService, env.Env().String("SERVICE_NAME")),
    19  		Tag(TagEnv, env.Env().String("SERVICE_ENV")),
    20  		Tag(TagContainer, env.Env().String("HOSTNAME")),
    21  	)
    22  }
    23  
    24  // AddDefaultTags adds default tags to a stats collector.
    25  func AddDefaultTags(collector Collector, serviceName, serviceEnv, container string) {
    26  	if collector == nil {
    27  		return
    28  	}
    29  	collector.AddDefaultTags(
    30  		Tag(TagService, serviceName),
    31  		Tag(TagEnv, serviceEnv),
    32  		Tag(TagContainer, container),
    33  	)
    34  }