generated from theparanoids/.github
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
export otel metrics for gensign panic (#218)
- Loading branch information
Showing
8 changed files
with
79 additions
and
17 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
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
File renamed without changes.
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,40 @@ | ||
package otellib | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/theparanoids/ysshra/csr" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
const ( | ||
scopeName = "github.com/theparanoids/ysshra/otellib" | ||
ysshraPanic = "ysshra.panic" | ||
) | ||
|
||
var meter metric.Meter | ||
|
||
// InitMeter initializes the oTel meter for ysshra. | ||
func InitMeter() { | ||
meter = otel.GetMeterProvider().Meter(scopeName) | ||
} | ||
|
||
// ExportPanicMetric exports a panic metric to the oTel meter. | ||
func ExportPanicMetric(ctx context.Context, param *csr.ReqParam, msg string) { | ||
var err error | ||
panicCounter, err := meter.Int64Counter( | ||
ysshraPanic, | ||
metric.WithUnit("1"), | ||
metric.WithDescription("Count the number of HTTP handler panic"), | ||
) | ||
if err != nil { | ||
log.Printf("Error creating metric for panic: %v\n", err) | ||
} | ||
panicCounter.Add(ctx, 1, metric.WithAttributes( | ||
attribute.String("gensign.transid", param.TransID), | ||
attribute.String("panic.message", msg), | ||
)) | ||
} |