Skip to content

Commit

Permalink
Merge pull request #1739 from Permify/fix/handle-os-setenv-errors-gcp…
Browse files Browse the repository at this point in the history
…-telemetry-logging

fix: handle errors from os.Setenv in GCP telemetry and logging
  • Loading branch information
tolgaOzen authored Oct 30, 2024
2 parents 4fac29a + aeccbe5 commit 90bc248
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions internal/engines/subjectFilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,10 @@ func (engine *SubjectFilter) subjectFilterDirectRelation(
// setChild generates a SubjectFilterFunction by applying a SubjectFilterCombiner
// to a set of child permission lookups, given a request and a list of Child objects.
func (engine *SubjectFilter) setChild(
ctx context.Context, // The context for carrying out the operation
ctx context.Context, // The context for carrying out the operation
request *base.PermissionLookupSubjectRequest, // The request containing parameters for lookup
children []*base.Child, // The children of a particular node in the permission schema
combiner SubjectFilterCombiner, // A function to combine the results from multiple lookup functions
children []*base.Child, // The children of a particular node in the permission schema
combiner SubjectFilterCombiner, // A function to combine the results from multiple lookup functions
) SubjectFilterFunction {
var functions []SubjectFilterFunction // Array of functions to store lookup functions for each child

Expand Down
11 changes: 7 additions & 4 deletions pkg/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"log/slog"
"os"

"github.com/Permify/permify/pkg/telemetry"
"github.com/Permify/permify/pkg/telemetry/logexporters"
"github.com/Permify/sloggcp"
"github.com/agoda-com/opentelemetry-go/otelslog"

"github.com/Permify/permify/pkg/telemetry"
"github.com/Permify/permify/pkg/telemetry/logexporters"
)

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

// Set credentials for Google Cloud access
if creds != "" {
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", creds)
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", creds); err != nil {
return nil, err
}
}

// Initialize GCP-specific log handler
Expand Down
5 changes: 3 additions & 2 deletions pkg/telemetry/meterexporters/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

// NewGCP creates a new Google Cloud metric exporter with optional headers for credentials and project ID.
func NewGCP(headers map[string]string) (metric.Exporter, error) {

if credentials, exists := headers["google-application-credentials"]; exists && credentials != "" {
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials)
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials); err != nil {
return nil, err
}
}

if projectID, exists := headers["google-cloud-project"]; exists && projectID != "" {
Expand Down
5 changes: 3 additions & 2 deletions pkg/telemetry/tracerexporters/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

// NewGCP creates a new Google Cloud tracer with optional headers for credentials and project ID.
func NewGCP(headers map[string]string) (sdktrace.SpanExporter, error) {

if credentials, exists := headers["google-application-credentials"]; exists && credentials != "" {
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials)
if err := os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", credentials); err != nil {
return nil, err
}
}

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

0 comments on commit 90bc248

Please sign in to comment.