-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add some util functions for tracer pkg and metric pkg
- Loading branch information
1 parent
e42bdbc
commit efae8be
Showing
7 changed files
with
85 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ import ( | |
|
||
func init() { | ||
if env.BoolFromEnv(constant.EnvKeyOTLPEnabled) { | ||
initProvider() | ||
InitProvider() | ||
} | ||
} |
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,46 @@ | ||
package metric | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
// Flush flushes all pending telemetry. | ||
// | ||
// This method honors the deadline or cancellation of ctx. An appropriate | ||
// error will be returned in these situations. There is no guaranteed that all | ||
// telemetry be flushed or all resources have been released in these | ||
// situations. | ||
// | ||
// This method is safe to call concurrently. | ||
func Flush(ctx context.Context) error { | ||
if provider != nil { | ||
return provider.ForceFlush(ctx) | ||
} else { | ||
return errors.New("no meter provider was initialized") | ||
} | ||
} | ||
|
||
// Shutdown shuts down the MeterProvider flushing all pending telemetry and | ||
// releasing any held computational resources. | ||
// | ||
// This call is idempotent. The first call will perform all flush and | ||
// releasing operations. Subsequent calls will perform no action and will | ||
// return an error stating this. | ||
// | ||
// Measurements made by instruments from meters this MeterProvider created | ||
// will not be exported after Shutdown is called. | ||
// | ||
// This method honors the deadline or cancellation of ctx. An appropriate | ||
// error will be returned in these situations. There is no guaranteed that all | ||
// telemetry be flushed or all resources have been released in these | ||
// situations. | ||
// | ||
// This method is safe to call concurrently. | ||
func Shutdown(ctx context.Context) error { | ||
if provider != nil { | ||
return provider.Shutdown(ctx) | ||
} else { | ||
return errors.New("no meter provider was initialized") | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,6 @@ import ( | |
|
||
func init() { | ||
if env.BoolFromEnv(constant.EnvKeyOTLPEnabled) { | ||
initProvider() | ||
InitProvider() | ||
} | ||
} |
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,27 @@ | ||
package tracer | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
// Shutdown shuts down TracerProvider. All registered span processors are shut down | ||
// in the order they were registered and any held computational resources are released. | ||
// After Shutdown is called, all methods are no-ops. | ||
func Shutdown(ctx context.Context) error { | ||
if provider != nil { | ||
return provider.Shutdown(ctx) | ||
} else { | ||
return errors.New("no tracer provider was initialized") | ||
} | ||
} | ||
|
||
// Flush immediately exports all spans that have not yet been exported for | ||
// all the registered span processors | ||
func Flush(ctx context.Context) error { | ||
if provider != nil { | ||
return provider.ForceFlush(ctx) | ||
} else { | ||
return errors.New("no tracer provider was initialized") | ||
} | ||
} |