1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-11-25 22:41:46 +02:00
Files
opentelemetry-go/semconv/v1.33.0/cicdconv/metric.go

523 lines
16 KiB
Go
Raw Normal View History

Generate `semconv/v1.33.0` (#6799) - Generate the new `semconv/v1.33.0` package and all sub-packages - Fix the metric util package generation to support `int64` attribute definitions ## [`v1.33.0` semantic convention release notes](https://github.com/open-telemetry/semantic-conventions/releases/tag/v1.33.0): <div data-pjax="true" data-test-selector="body-content" data-view-component="true" class="markdown-body my-3"><p>This release marks the first where the core of database semantic conventions have stabilized.</p> <h3>🛑 Breaking changes 🛑</h3> <ul> <li><code>db</code>: Add <code>db.query.parameter</code>, replace relevant usages of <code>db.operation.parameter</code> (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2093" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2093/hovercard">#2093</a>)</li> <li><code>db</code>: Make <code>db.response.returned_rows</code> opt-in on <code>release_candidate</code> spans (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2211" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2211/hovercard">#2211</a>)</li> <li><code>db</code>: Use <code>|</code> as the separator when <code>db.namespace</code> is a concatenation of multiple components. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2067" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2067/hovercard">#2067</a>)</li> <li><code>feature_flag</code>: Rename <code>feature_flag.provider_name</code> to <code>feature_flag.provider.name</code> (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1982" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1982/hovercard">#1982</a>)</li> <li><code>feature_flag</code>: Use generic <code>error.message</code> in feature flag evaluation event (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1994" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1994/hovercard">#1994</a>)</li> <li><code>gen-ai</code>: Refine the values for <code>gen_ai.system</code> related to Google's AI endpoints. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1950" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1950/hovercard">#1950</a>)<br> Enable sharing of attributes between Vertex AI and Gemini through a common prefix.</li> <li><code>k8s</code>: Make k8s Node and Pod labels optional (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2079" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2079/hovercard">#2079</a>)</li> <li><code>otel</code>: Rename span health metrics to remove the .count suffixes (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1979" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1979/hovercard">#1979</a>)</li> </ul> <h3>🚀 New components 🚀</h3> <ul> <li><code>db</code>: Adding semantic conventions for <code>oracledb</code> instrumentations. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2612">#2612</a>)<br> Oracle Database semantic conventions.</li> <li><code>browser</code>: Add browser web vitals event. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1940" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/1940/hovercard">#1940</a>)</li> </ul> <h3>💡 Enhancements 💡</h3> <ul> <li><code>cicd</code>: Add resource conventions for CICD systems and define spans for CICD pipeline runs. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1713" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1713/hovercard">#1713</a>)<br> Define spans <code>cicd.pipeline.run.server</code> and <code>cicd.pipeline.task.internal</code>.<br> Add <code>cicd.pipeline.action.name</code>, <code>cicd.worker.id</code>, <code>cicd.worker.name</code>, <code>cicd.worker.url.full</code> and<code>cicd.pipeline.task.run.result</code> to attribute registry.<br> Define resources <code>cicd.pipeline</code>, <code>cicd.pipeline.run</code> and <code>cicd.worker</code>.<br> Add entity associations in cicd metrics for these new cicd resources.</li> <li><code>vcs</code>: Add resource conventions for VCS systems and VCS references. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1713" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1713/hovercard">#1713</a>)<br> Define resources <code>vcs.repo</code> and <code>vcs.ref</code>.<br> Add entity associations in vcs metrics for these new vcs resources.</li> <li><code>gen-ai</code>: Adding span for invoke agent (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1842" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1842/hovercard">#1842</a>)</li> <li><code>gen-ai</code>: Adding gen_ai.tool.description to the span attributes (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2087" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2087/hovercard">#2087</a>)</li> <li><code>gen-ai</code>: Separate inference and embeddings span definitions, remove irrelevant attributes from the create agent span. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1924" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1924/hovercard">#1924</a>, <a href="https://github.com/open-telemetry/semantic-conventions/issues/2122" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2122/hovercard">#2122</a>)</li> <li><code>general</code>: Provide guidance on modeling lat/lon, x/y, etc (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2145" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2145/hovercard">#2145</a>)</li> <li><code>db</code>: Move <code>db.query.parameter.&lt;key&gt;</code> from release_candidate back to development. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2194" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2194/hovercard">#2194</a>)</li> <li><code>db</code>: Mark database semantic conventions as stable for MariaDB, Microsoft SQL Server, MySQL, and PostgreSQL. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2199" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2199/hovercard">#2199</a>)</li> <li><code>db</code>: Make <code>db.operation.name</code> required where it's available, add recommendation for instrumentation point. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2200" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2200/hovercard">#2200</a>, <a href="https://github.com/open-telemetry/semantic-conventions/issues/2098" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2098/hovercard">#2098</a>)</li> <li><code>db</code>: Add <code>db.stored_procedure.name</code> to the general span conventions (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2205" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2205/hovercard">#2205</a>)</li> <li><code>db</code>: Add an option to generate <code>db.query.summary</code> from operation name and target, remove it from CosmosDB. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2206" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2206/hovercard">#2206</a>)</li> <li><code>db</code>: Add <code>db.operation.name</code> and <code>db.collection.name</code> to SQL for higher-level APIs (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2207" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2207/hovercard">#2207</a>)</li> <li><code>jvm</code>: Add <code>jvm.file_descriptor.count</code> as an in-development metric to track the number of open file descriptors as reported by the JVM. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1838" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1838/hovercard">#1838</a>)</li> <li><code>jvm</code>: Add <code>jvm.gc.cause</code> to metric <code>jvm.gc.duration</code> as an opt-in attribute to track gc cause. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2065" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2065/hovercard">#2065</a>)</li> <li><code>process</code>: Add process.environment_variable. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/672" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/672/hovercard">#672</a>)</li> <li><code>app</code>: Defines two new click events for the app domain (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2070" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2070/hovercard">#2070</a>)</li> <li><code>code</code>: Mark <code>code.*</code> semantic conventions as stable (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1377" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1377/hovercard">#1377</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s CronJob labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2138" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2138/hovercard">#2138</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s DaemonSet labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2136" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2136/hovercard">#2136</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s Deployment labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2134" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2134/hovercard">#2134</a>)</li> <li><code>system</code>: Added entity association template rendering and policies. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1276" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1276/hovercard">#1276</a>)</li> <li><code>gen_ai</code>: Document <code>generate_content</code> as a permissible value of <code>gen_ai.operation.name</code>. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2048" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2048/hovercard">#2048</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s Job labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2137" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2137/hovercard">#2137</a>)</li> <li><code>otel</code>: Adds SDK self-monitoring metrics for metric processing (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2016" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2016/hovercard">#2016</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s Namespace labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2131" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2131/hovercard">#2131</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s Node labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2079" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2079/hovercard">#2079</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s ReplicaSet labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2132" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2132/hovercard">#2132</a>)</li> <li><code>otel</code>: Adds SDK self-monitoring metric for exporter call duration (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1906" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1906/hovercard">#1906</a>)</li> <li><code>k8s</code>: Introduce semantic conventions for k8s StatefulSet labels and annotations (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2135" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2135/hovercard">#2135</a>)</li> </ul> <h3>🧰 Bug fixes 🧰</h3> <ul> <li><code>gen-ai</code>: Removed irrelevant response attributes on GenAI create agent span. (<a href="https://github.com/open-telemetry/semantic-conventions/issues/1924" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/1924/hovercard">#1924</a>, <a href="https://github.com/open-telemetry/semantic-conventions/issues/2116" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2116/hovercard">#2116</a>)</li> <li><code>vcs</code>: Fix typo in gitea name (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2057" data-hovercard-type="issue" data-hovercard-url="/open-telemetry/semantic-conventions/issues/2057/hovercard">#2057</a>)</li> <li><code>gen-ai</code>: Add invoke_agent as a member of gen_ai.operation.name (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2160" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2160/hovercard">#2160</a>)</li> <li><code>db</code>: Clarify <code>db.query.summary</code> for stored procedures (<a href="https://github.com/open-telemetry/semantic-conventions/issues/2218" data-hovercard-type="pull_request" data-hovercard-url="/open-telemetry/semantic-conventions/pull/2218/hovercard">#2218</a>)</li> </ul>
2025-05-22 07:56:01 -07:00
// Code generated from semantic convention specification. DO NOT EDIT.
// Package httpconv provides types and functionality for OpenTelemetry semantic
// conventions in the "cicd" namespace.
package cicdconv
import (
"context"
"sync"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/metric/noop"
)
var (
addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
)
// PipelineResultAttr is an attribute conforming to the cicd.pipeline.result
// semantic conventions. It represents the result of a pipeline run.
type PipelineResultAttr string
var (
// PipelineResultSuccess is the pipeline run finished successfully.
PipelineResultSuccess PipelineResultAttr = "success"
// PipelineResultFailure is the pipeline run did not finish successfully, eg.
// due to a compile error or a failing test. Such failures are usually detected
// by non-zero exit codes of the tools executed in the pipeline run.
PipelineResultFailure PipelineResultAttr = "failure"
// PipelineResultError is the pipeline run failed due to an error in the CICD
// system, eg. due to the worker being killed.
PipelineResultError PipelineResultAttr = "error"
// PipelineResultTimeout is a timeout caused the pipeline run to be interrupted.
PipelineResultTimeout PipelineResultAttr = "timeout"
// PipelineResultCancellation is the pipeline run was cancelled, eg. by a user
// manually cancelling the pipeline run.
PipelineResultCancellation PipelineResultAttr = "cancellation"
// PipelineResultSkip is the pipeline run was skipped, eg. due to a precondition
// not being met.
PipelineResultSkip PipelineResultAttr = "skip"
)
// PipelineRunStateAttr is an attribute conforming to the cicd.pipeline.run.state
// semantic conventions. It represents the pipeline run goes through these states
// during its lifecycle.
type PipelineRunStateAttr string
var (
// PipelineRunStatePending is the run pending state spans from the event
// triggering the pipeline run until the execution of the run starts (eg. time
// spent in a queue, provisioning agents, creating run resources).
PipelineRunStatePending PipelineRunStateAttr = "pending"
// PipelineRunStateExecuting is the executing state spans the execution of any
// run tasks (eg. build, test).
PipelineRunStateExecuting PipelineRunStateAttr = "executing"
// PipelineRunStateFinalizing is the finalizing state spans from when the run
// has finished executing (eg. cleanup of run resources).
PipelineRunStateFinalizing PipelineRunStateAttr = "finalizing"
)
// WorkerStateAttr is an attribute conforming to the cicd.worker.state semantic
// conventions. It represents the state of a CICD worker / agent.
type WorkerStateAttr string
var (
// WorkerStateAvailable is the worker is not performing work for the CICD
// system. It is available to the CICD system to perform work on (online /
// idle).
WorkerStateAvailable WorkerStateAttr = "available"
// WorkerStateBusy is the worker is performing work for the CICD system.
WorkerStateBusy WorkerStateAttr = "busy"
// WorkerStateOffline is the worker is not available to the CICD system
// (disconnected / down).
WorkerStateOffline WorkerStateAttr = "offline"
)
// ErrorTypeAttr is an attribute conforming to the error.type semantic
// conventions. It represents the describes a class of error the operation ended
// with.
type ErrorTypeAttr string
var (
// ErrorTypeOther is a fallback error value to be used when the instrumentation
// doesn't define a custom value.
ErrorTypeOther ErrorTypeAttr = "_OTHER"
)
// PipelineRunActive is an instrument used to record metric values conforming to
// the "cicd.pipeline.run.active" semantic conventions. It represents the number
// of pipeline runs currently active in the system by state.
type PipelineRunActive struct {
metric.Int64UpDownCounter
}
// NewPipelineRunActive returns a new PipelineRunActive instrument.
func NewPipelineRunActive(
m metric.Meter,
opt ...metric.Int64UpDownCounterOption,
) (PipelineRunActive, error) {
// Check if the meter is nil.
if m == nil {
return PipelineRunActive{noop.Int64UpDownCounter{}}, nil
}
i, err := m.Int64UpDownCounter(
"cicd.pipeline.run.active",
append([]metric.Int64UpDownCounterOption{
metric.WithDescription("The number of pipeline runs currently active in the system by state."),
metric.WithUnit("{run}"),
}, opt...)...,
)
if err != nil {
return PipelineRunActive{noop.Int64UpDownCounter{}}, err
}
return PipelineRunActive{i}, nil
}
// Inst returns the underlying metric instrument.
func (m PipelineRunActive) Inst() metric.Int64UpDownCounter {
return m.Int64UpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (PipelineRunActive) Name() string {
return "cicd.pipeline.run.active"
}
// Unit returns the semantic convention unit of the instrument
func (PipelineRunActive) Unit() string {
return "{run}"
}
// Description returns the semantic convention description of the instrument
func (PipelineRunActive) Description() string {
return "The number of pipeline runs currently active in the system by state."
}
// Add adds incr to the existing count.
//
// The pipelineName is the the human readable name of the pipeline within a CI/CD
// system.
//
// The pipelineRunState is the the pipeline run goes through these states during
// its lifecycle.
func (m PipelineRunActive) Add(
ctx context.Context,
incr int64,
pipelineName string,
pipelineRunState PipelineRunStateAttr,
attrs ...attribute.KeyValue,
) {
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.pipeline.name", pipelineName),
attribute.String("cicd.pipeline.run.state", string(pipelineRunState)),
)...,
),
)
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}
// PipelineRunDuration is an instrument used to record metric values conforming
// to the "cicd.pipeline.run.duration" semantic conventions. It represents the
// duration of a pipeline run grouped by pipeline, state and result.
type PipelineRunDuration struct {
metric.Float64Histogram
}
// NewPipelineRunDuration returns a new PipelineRunDuration instrument.
func NewPipelineRunDuration(
m metric.Meter,
opt ...metric.Float64HistogramOption,
) (PipelineRunDuration, error) {
// Check if the meter is nil.
if m == nil {
return PipelineRunDuration{noop.Float64Histogram{}}, nil
}
i, err := m.Float64Histogram(
"cicd.pipeline.run.duration",
append([]metric.Float64HistogramOption{
metric.WithDescription("Duration of a pipeline run grouped by pipeline, state and result."),
metric.WithUnit("s"),
}, opt...)...,
)
if err != nil {
return PipelineRunDuration{noop.Float64Histogram{}}, err
}
return PipelineRunDuration{i}, nil
}
// Inst returns the underlying metric instrument.
func (m PipelineRunDuration) Inst() metric.Float64Histogram {
return m.Float64Histogram
}
// Name returns the semantic convention name of the instrument.
func (PipelineRunDuration) Name() string {
return "cicd.pipeline.run.duration"
}
// Unit returns the semantic convention unit of the instrument
func (PipelineRunDuration) Unit() string {
return "s"
}
// Description returns the semantic convention description of the instrument
func (PipelineRunDuration) Description() string {
return "Duration of a pipeline run grouped by pipeline, state and result."
}
// Record records val to the current distribution.
//
// The pipelineName is the the human readable name of the pipeline within a CI/CD
// system.
//
// The pipelineRunState is the the pipeline run goes through these states during
// its lifecycle.
//
// All additional attrs passed are included in the recorded value.
func (m PipelineRunDuration) Record(
ctx context.Context,
val float64,
pipelineName string,
pipelineRunState PipelineRunStateAttr,
attrs ...attribute.KeyValue,
) {
o := recOptPool.Get().(*[]metric.RecordOption)
defer func() {
*o = (*o)[:0]
recOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.pipeline.name", pipelineName),
attribute.String("cicd.pipeline.run.state", string(pipelineRunState)),
)...,
),
)
m.Float64Histogram.Record(ctx, val, *o...)
}
// AttrPipelineResult returns an optional attribute for the
// "cicd.pipeline.result" semantic convention. It represents the result of a
// pipeline run.
func (PipelineRunDuration) AttrPipelineResult(val PipelineResultAttr) attribute.KeyValue {
return attribute.String("cicd.pipeline.result", string(val))
}
// AttrErrorType returns an optional attribute for the "error.type" semantic
// convention. It represents the describes a class of error the operation ended
// with.
func (PipelineRunDuration) AttrErrorType(val ErrorTypeAttr) attribute.KeyValue {
return attribute.String("error.type", string(val))
}
// PipelineRunErrors is an instrument used to record metric values conforming to
// the "cicd.pipeline.run.errors" semantic conventions. It represents the number
// of errors encountered in pipeline runs (eg. compile, test failures).
type PipelineRunErrors struct {
metric.Int64Counter
}
// NewPipelineRunErrors returns a new PipelineRunErrors instrument.
func NewPipelineRunErrors(
m metric.Meter,
opt ...metric.Int64CounterOption,
) (PipelineRunErrors, error) {
// Check if the meter is nil.
if m == nil {
return PipelineRunErrors{noop.Int64Counter{}}, nil
}
i, err := m.Int64Counter(
"cicd.pipeline.run.errors",
append([]metric.Int64CounterOption{
metric.WithDescription("The number of errors encountered in pipeline runs (eg. compile, test failures)."),
metric.WithUnit("{error}"),
}, opt...)...,
)
if err != nil {
return PipelineRunErrors{noop.Int64Counter{}}, err
}
return PipelineRunErrors{i}, nil
}
// Inst returns the underlying metric instrument.
func (m PipelineRunErrors) Inst() metric.Int64Counter {
return m.Int64Counter
}
// Name returns the semantic convention name of the instrument.
func (PipelineRunErrors) Name() string {
return "cicd.pipeline.run.errors"
}
// Unit returns the semantic convention unit of the instrument
func (PipelineRunErrors) Unit() string {
return "{error}"
}
// Description returns the semantic convention description of the instrument
func (PipelineRunErrors) Description() string {
return "The number of errors encountered in pipeline runs (eg. compile, test failures)."
}
// Add adds incr to the existing count.
//
// The pipelineName is the the human readable name of the pipeline within a CI/CD
// system.
//
// The errorType is the describes a class of error the operation ended with.
//
// There might be errors in a pipeline run that are non fatal (eg. they are
// suppressed) or in a parallel stage multiple stages could have a fatal error.
// This means that this error count might not be the same as the count of metric
// `cicd.pipeline.run.duration` with run result `failure`.
func (m PipelineRunErrors) Add(
ctx context.Context,
incr int64,
pipelineName string,
errorType ErrorTypeAttr,
attrs ...attribute.KeyValue,
) {
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.pipeline.name", pipelineName),
attribute.String("error.type", string(errorType)),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}
// SystemErrors is an instrument used to record metric values conforming to the
// "cicd.system.errors" semantic conventions. It represents the number of errors
// in a component of the CICD system (eg. controller, scheduler, agent).
type SystemErrors struct {
metric.Int64Counter
}
// NewSystemErrors returns a new SystemErrors instrument.
func NewSystemErrors(
m metric.Meter,
opt ...metric.Int64CounterOption,
) (SystemErrors, error) {
// Check if the meter is nil.
if m == nil {
return SystemErrors{noop.Int64Counter{}}, nil
}
i, err := m.Int64Counter(
"cicd.system.errors",
append([]metric.Int64CounterOption{
metric.WithDescription("The number of errors in a component of the CICD system (eg. controller, scheduler, agent)."),
metric.WithUnit("{error}"),
}, opt...)...,
)
if err != nil {
return SystemErrors{noop.Int64Counter{}}, err
}
return SystemErrors{i}, nil
}
// Inst returns the underlying metric instrument.
func (m SystemErrors) Inst() metric.Int64Counter {
return m.Int64Counter
}
// Name returns the semantic convention name of the instrument.
func (SystemErrors) Name() string {
return "cicd.system.errors"
}
// Unit returns the semantic convention unit of the instrument
func (SystemErrors) Unit() string {
return "{error}"
}
// Description returns the semantic convention description of the instrument
func (SystemErrors) Description() string {
return "The number of errors in a component of the CICD system (eg. controller, scheduler, agent)."
}
// Add adds incr to the existing count.
//
// The systemComponent is the the name of a component of the CICD system.
//
// The errorType is the describes a class of error the operation ended with.
//
// Errors in pipeline run execution are explicitly excluded. Ie a test failure is
// not counted in this metric.
func (m SystemErrors) Add(
ctx context.Context,
incr int64,
systemComponent string,
errorType ErrorTypeAttr,
attrs ...attribute.KeyValue,
) {
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.system.component", systemComponent),
attribute.String("error.type", string(errorType)),
)...,
),
)
m.Int64Counter.Add(ctx, incr, *o...)
}
// WorkerCount is an instrument used to record metric values conforming to the
// "cicd.worker.count" semantic conventions. It represents the number of workers
// on the CICD system by state.
type WorkerCount struct {
metric.Int64UpDownCounter
}
// NewWorkerCount returns a new WorkerCount instrument.
func NewWorkerCount(
m metric.Meter,
opt ...metric.Int64UpDownCounterOption,
) (WorkerCount, error) {
// Check if the meter is nil.
if m == nil {
return WorkerCount{noop.Int64UpDownCounter{}}, nil
}
i, err := m.Int64UpDownCounter(
"cicd.worker.count",
append([]metric.Int64UpDownCounterOption{
metric.WithDescription("The number of workers on the CICD system by state."),
metric.WithUnit("{count}"),
}, opt...)...,
)
if err != nil {
return WorkerCount{noop.Int64UpDownCounter{}}, err
}
return WorkerCount{i}, nil
}
// Inst returns the underlying metric instrument.
func (m WorkerCount) Inst() metric.Int64UpDownCounter {
return m.Int64UpDownCounter
}
// Name returns the semantic convention name of the instrument.
func (WorkerCount) Name() string {
return "cicd.worker.count"
}
// Unit returns the semantic convention unit of the instrument
func (WorkerCount) Unit() string {
return "{count}"
}
// Description returns the semantic convention description of the instrument
func (WorkerCount) Description() string {
return "The number of workers on the CICD system by state."
}
// Add adds incr to the existing count.
//
// The workerState is the the state of a CICD worker / agent.
func (m WorkerCount) Add(
ctx context.Context,
incr int64,
workerState WorkerStateAttr,
attrs ...attribute.KeyValue,
) {
o := addOptPool.Get().(*[]metric.AddOption)
defer func() {
*o = (*o)[:0]
addOptPool.Put(o)
}()
*o = append(
*o,
metric.WithAttributes(
append(
attrs,
attribute.String("cicd.worker.state", string(workerState)),
)...,
),
)
m.Int64UpDownCounter.Add(ctx, incr, *o...)
}