Skip to content

Commit

Permalink
observability: add custom tags and location tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lidizheng committed Mar 10, 2022
1 parent 2cb0a9a commit 7b2a650
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions observability/exporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func newCloudLoggingExporter(ctx context.Context, projectID string) (*cloudLoggi
if err != nil {
return nil, fmt.Errorf("failed to create cloudLoggingExporter: %v", err)
}
logger.Infof("successfully created cloudLoggingExporter")
defer logger.Infof("successfully created cloudLoggingExporter")
return &cloudLoggingExporter{
projectID: projectID,
client: c,
logger: c.Logger("grpc"),
logger: c.Logger("grpc", gcplogging.CommonLabels(getCustomTags())),
}, nil
}

Expand Down
39 changes: 39 additions & 0 deletions observability/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* Copyright 2022 gRPC 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 observability

import (
"os"
"strings"
)

const envPrefixCustomTags = "GRPC_OBSERVABILITY_"

func getCustomTags() map[string]string {
m := make(map[string]string)
for _, e := range os.Environ() {
if !strings.HasPrefix(e, envPrefixCustomTags) {
continue
}
if i := strings.Index(e, "="); i >= 0 {
m[e[:i]] = e[i+1:]
}
}
return m
}

0 comments on commit 7b2a650

Please sign in to comment.