Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to confirm known bug #1700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions opentelemetry-sdk/src/metrics/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,28 @@ where
mod tests {
use std::sync::Arc;

use opentelemetry::metrics::{InstrumentProvider, MetricsError, Unit};
use opentelemetry::metrics::{InstrumentProvider, MeterProvider, MetricsError, Unit};

use super::{
InstrumentValidationPolicy, SdkMeter, INSTRUMENT_NAME_FIRST_ALPHABETIC,
INSTRUMENT_NAME_INVALID_CHAR, INSTRUMENT_NAME_LENGTH, INSTRUMENT_UNIT_INVALID_CHAR,
INSTRUMENT_UNIT_LENGTH,
};
use crate::{metrics::pipeline::Pipelines, Resource, Scope};
use crate::{
metrics::{pipeline::Pipelines, SdkMeterProvider},
Resource, Scope,
};

#[test]
#[ignore = "See issue https://github.com/open-telemetry/opentelemetry-rust/issues/1699"]
fn test_instrument_creation() {
let provider = SdkMeterProvider::builder().build();
let meter = provider.meter("test");
assert!(meter.u64_counter("test").try_init().is_ok());
let result = meter.u64_counter("test with invalid name").try_init();
// this assert fails, as result is always ok variant.
assert!(result.is_err());
}

#[test]
fn test_instrument_config_validation() {
Expand All @@ -787,9 +801,9 @@ mod tests {
("a".repeat(255).leak(), ""),
("a".repeat(256).leak(), INSTRUMENT_NAME_LENGTH),
("invalid name", INSTRUMENT_NAME_INVALID_CHAR),
// hyphens are now valid characters in the specification.
// https://github.com/open-telemetry/opentelemetry-specification/pull/3684
("allow/hyphen", ""),
("allow/slash", ""),
("allow_under_score", ""),
("allow.dots.ok", ""),
];
for (name, expected_error) in instrument_name_test_cases {
let assert = |result: Result<_, MetricsError>| {
Expand Down Expand Up @@ -865,6 +879,9 @@ mod tests {
),
("utf8char锈", INSTRUMENT_UNIT_INVALID_CHAR),
("kb", ""),
("Kb/sec", ""),
("%", ""),
("", ""),
];

for (unit, expected_error) in instrument_unit_test_cases {
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry/src/metrics/noop.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! # No-op OpenTelemetry Metrics Implementation
//!
//! This implementation is returned as the global Meter if no `Meter`
//! has been set. It is also useful for testing purposes as it is intended
//! to have minimal resource utilization and runtime impact.
//! This implementation is returned as the global Meter if no `MeterProvider`
//! has been set. It is expected to have minimal resource utilization and
//! runtime impact.
use crate::{
metrics::{
AsyncInstrument, CallbackRegistration, InstrumentProvider, Meter, MeterProvider, Observer,
Expand Down
Loading