-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow controlling of StartCall info logging from a service runt…
…ime (#422)
- Loading branch information
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 Outreach Corporation. All Rights Reserved. | ||
|
||
// Description: This file contains constants and tools for controlling trace.Start/EndCall logging | ||
|
||
package trace | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/getoutreach/gobox/pkg/log" | ||
) | ||
|
||
type InfoLoggingResolved int32 | ||
|
||
const ( | ||
InfoLoggingDefault InfoLoggingResolved = 0 | ||
InfoLoggingEnabled InfoLoggingResolved = 1 | ||
InfoLoggingDisabled InfoLoggingResolved = 2 | ||
) | ||
|
||
type InfoLoggingResolver = func(ctx context.Context, operation string) InfoLoggingResolved | ||
|
||
// ResolvedLogging returns signals trace.EndCall whether to enable/disable info logging | ||
func ResolvedLogging(logging InfoLoggingResolved) log.Marshaler { | ||
if logging == InfoLoggingDefault { | ||
return nil | ||
} | ||
if logging == InfoLoggingEnabled { | ||
return WithInfoLoggingEnabled() | ||
} | ||
return WithInfoLoggingDisabled() | ||
} | ||
|
||
func ReevaluateLogging(ctx context.Context, resolver InfoLoggingResolver) { | ||
logging := resolver(ctx, GetCallName(ctx)) | ||
if logging == InfoLoggingDefault { | ||
return | ||
} | ||
callInfo := callTracker.Info(ctx) | ||
callInfo.Opts.EnableInfoLogging = logging == InfoLoggingEnabled | ||
} |