Skip to content

Commit 90bc248

Browse files
authored
Merge pull request #1739 from Permify/fix/handle-os-setenv-errors-gcp-telemetry-logging
fix: handle errors from os.Setenv in GCP telemetry and logging
2 parents 4fac29a + aeccbe5 commit 90bc248

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

internal/engines/subjectFilter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ func (engine *SubjectFilter) subjectFilterDirectRelation(
517517
// setChild generates a SubjectFilterFunction by applying a SubjectFilterCombiner
518518
// to a set of child permission lookups, given a request and a list of Child objects.
519519
func (engine *SubjectFilter) setChild(
520-
ctx context.Context, // The context for carrying out the operation
520+
ctx context.Context, // The context for carrying out the operation
521521
request *base.PermissionLookupSubjectRequest, // The request containing parameters for lookup
522-
children []*base.Child, // The children of a particular node in the permission schema
523-
combiner SubjectFilterCombiner, // A function to combine the results from multiple lookup functions
522+
children []*base.Child, // The children of a particular node in the permission schema
523+
combiner SubjectFilterCombiner, // A function to combine the results from multiple lookup functions
524524
) SubjectFilterFunction {
525525
var functions []SubjectFilterFunction // Array of functions to store lookup functions for each child
526526

pkg/cmd/log.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"log/slog"
88
"os"
99

10-
"github.com/Permify/permify/pkg/telemetry"
11-
"github.com/Permify/permify/pkg/telemetry/logexporters"
1210
"github.com/Permify/sloggcp"
1311
"github.com/agoda-com/opentelemetry-go/otelslog"
12+
13+
"github.com/Permify/permify/pkg/telemetry"
14+
"github.com/Permify/permify/pkg/telemetry/logexporters"
1415
)
1516

1617
// HandlerFactory - Create log handler according to given params
17-
func HandlerFactory(name string, endpoint string, insecure bool, urlpath string, headers map[string]string, protocol string, level slog.Leveler) (slog.Handler, error) {
18+
func HandlerFactory(name, endpoint string, insecure bool, urlpath string, headers map[string]string, protocol string, level slog.Leveler) (slog.Handler, error) {
1819
switch name {
1920
case "otlp", "otlp-http", "otlp-grpc":
2021
return NewOTLPHandler(endpoint, insecure, urlpath, headers, protocol, level.Level())
@@ -53,7 +54,9 @@ func NewGCPHandler(headers map[string]string, level slog.Leveler) (slog.Handler,
5354

5455
// Set credentials for Google Cloud access
5556
if creds != "" {
56-
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", creds)
57+
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", creds); err != nil {
58+
return nil, err
59+
}
5760
}
5861

5962
// Initialize GCP-specific log handler

pkg/telemetry/meterexporters/gcp.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99

1010
// NewGCP creates a new Google Cloud metric exporter with optional headers for credentials and project ID.
1111
func NewGCP(headers map[string]string) (metric.Exporter, error) {
12-
1312
if credentials, exists := headers["google-application-credentials"]; exists && credentials != "" {
14-
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials)
13+
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials); err != nil {
14+
return nil, err
15+
}
1516
}
1617

1718
if projectID, exists := headers["google-cloud-project"]; exists && projectID != "" {

pkg/telemetry/tracerexporters/gcp.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99

1010
// NewGCP creates a new Google Cloud tracer with optional headers for credentials and project ID.
1111
func NewGCP(headers map[string]string) (sdktrace.SpanExporter, error) {
12-
1312
if credentials, exists := headers["google-application-credentials"]; exists && credentials != "" {
14-
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials)
13+
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials); err != nil {
14+
return nil, err
15+
}
1516
}
1617

1718
if projectID, exists := headers["google-cloud-project"]; exists && projectID != "" {

0 commit comments

Comments
 (0)