Skip to content

Commit ccd5f08

Browse files
authored
Add test to confirm known bug (#1700)
1 parent 0b78252 commit ccd5f08

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

opentelemetry-sdk/src/metrics/meter.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,28 @@ where
762762
mod tests {
763763
use std::sync::Arc;
764764

765-
use opentelemetry::metrics::{InstrumentProvider, MetricsError, Unit};
765+
use opentelemetry::metrics::{InstrumentProvider, MeterProvider, MetricsError, Unit};
766766

767767
use super::{
768768
InstrumentValidationPolicy, SdkMeter, INSTRUMENT_NAME_FIRST_ALPHABETIC,
769769
INSTRUMENT_NAME_INVALID_CHAR, INSTRUMENT_NAME_LENGTH, INSTRUMENT_UNIT_INVALID_CHAR,
770770
INSTRUMENT_UNIT_LENGTH,
771771
};
772-
use crate::{metrics::pipeline::Pipelines, Resource, Scope};
772+
use crate::{
773+
metrics::{pipeline::Pipelines, SdkMeterProvider},
774+
Resource, Scope,
775+
};
776+
777+
#[test]
778+
#[ignore = "See issue https://github.com/open-telemetry/opentelemetry-rust/issues/1699"]
779+
fn test_instrument_creation() {
780+
let provider = SdkMeterProvider::builder().build();
781+
let meter = provider.meter("test");
782+
assert!(meter.u64_counter("test").try_init().is_ok());
783+
let result = meter.u64_counter("test with invalid name").try_init();
784+
// this assert fails, as result is always ok variant.
785+
assert!(result.is_err());
786+
}
773787

774788
#[test]
775789
fn test_instrument_config_validation() {
@@ -787,9 +801,9 @@ mod tests {
787801
("a".repeat(255).leak(), ""),
788802
("a".repeat(256).leak(), INSTRUMENT_NAME_LENGTH),
789803
("invalid name", INSTRUMENT_NAME_INVALID_CHAR),
790-
// hyphens are now valid characters in the specification.
791-
// https://github.com/open-telemetry/opentelemetry-specification/pull/3684
792-
("allow/hyphen", ""),
804+
("allow/slash", ""),
805+
("allow_under_score", ""),
806+
("allow.dots.ok", ""),
793807
];
794808
for (name, expected_error) in instrument_name_test_cases {
795809
let assert = |result: Result<_, MetricsError>| {
@@ -865,6 +879,9 @@ mod tests {
865879
),
866880
("utf8char锈", INSTRUMENT_UNIT_INVALID_CHAR),
867881
("kb", ""),
882+
("Kb/sec", ""),
883+
("%", ""),
884+
("", ""),
868885
];
869886

870887
for (unit, expected_error) in instrument_unit_test_cases {

opentelemetry/src/metrics/noop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! # No-op OpenTelemetry Metrics Implementation
22
//!
3-
//! This implementation is returned as the global Meter if no `Meter`
4-
//! has been set. It is also useful for testing purposes as it is intended
5-
//! to have minimal resource utilization and runtime impact.
3+
//! This implementation is returned as the global Meter if no `MeterProvider`
4+
//! has been set. It is expected to have minimal resource utilization and
5+
//! runtime impact.
66
use crate::{
77
metrics::{
88
AsyncInstrument, CallbackRegistration, InstrumentProvider, Meter, MeterProvider, Observer,

0 commit comments

Comments
 (0)