Ejemplo n.º 1
0
        /// <summary>
        /// Instantiates the base class.
        /// </summary>
        protected MetricBase(string name, string unit, string description, MetricSourceOptions options, ImmutableDictionary <string, string> tags = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            name = options.MetricNameTransformer(name);
            if (!options.MetricNameValidator(name))
            {
                throw new ArgumentException(name + " is not a valid metric name.", nameof(name));
            }

            var tagBuilder = options.DefaultTagsFrozen.ToBuilder();

            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    tagBuilder[tag.Key] = tag.Value;
                }
            }

            Name        = name;
            Unit        = unit;
            Description = description;
            Tags        = tagBuilder.ToImmutable();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Used by derived classes to pass the name, description and unit for a tag.
        /// </summary>
        protected TaggedMetricFactory(string name, string description, string unit, MetricSourceOptions options)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            name = options.MetricNameTransformer(name);
            if (!options.MetricNameValidator(name))
            {
                throw new ArgumentException(name + " is not a valid metric name.", nameof(name));
            }

            Name        = name;
            Description = description;
            Unit        = unit;
            Options     = options;
        }