예제 #1
0
 /// <summary>
 /// 获取导出器
 /// </summary>
 public BaseExporter GetExporter(Type type)
 {
     for (int i = 0; i < _exporters.Count; i++)
     {
         BaseExporter exporter = _exporters[i];
         if (exporter.GetType() == type)
         {
             return(exporter);
         }
     }
     throw new Exception($"Should never get here. {type}");
 }
예제 #2
0
        public BaseExportingMetricReader(BaseExporter <Metric> exporter)
        {
            Guard.Null(exporter, nameof(exporter));

            this.exporter = exporter;

            var exportorType = exporter.GetType();
            var attributes   = exportorType.GetCustomAttributes(typeof(AggregationTemporalityAttribute), true);

            if (attributes.Length > 0)
            {
                var attr = (AggregationTemporalityAttribute)attributes[attributes.Length - 1];
                this.PreferredAggregationTemporality = attr.Preferred;
                this.SupportedAggregationTemporality = attr.Supported;
            }

            attributes = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);
            if (attributes.Length > 0)
            {
                var attr = (ExportModesAttribute)attributes[attributes.Length - 1];
                this.supportedExportModes = attr.Supported;
            }

            if (exporter is IPullMetricExporter pullExporter)
            {
                if (this.supportedExportModes.HasFlag(ExportModes.Push))
                {
                    pullExporter.Collect = this.Collect;
                }
                else
                {
                    pullExporter.Collect = (timeoutMilliseconds) =>
                    {
                        using (PullMetricScope.Begin())
                        {
                            return(this.Collect(timeoutMilliseconds));
                        }
                    };
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseExportingMetricReader"/> class.
        /// </summary>
        /// <param name="exporter">Exporter instance to export Metrics to.</param>
        public BaseExportingMetricReader(BaseExporter <Metric> exporter)
        {
            Guard.ThrowIfNull(exporter);

            this.exporter = exporter;

            var exportorType = exporter.GetType();
            var attributes   = exportorType.GetCustomAttributes(typeof(ExportModesAttribute), true);

            if (attributes.Length > 0)
            {
                var attr = (ExportModesAttribute)attributes[attributes.Length - 1];
                this.supportedExportModes = attr.Supported;
            }

            if (exporter is IPullMetricExporter pullExporter)
            {
                if (this.supportedExportModes.HasFlag(ExportModes.Push))
                {
                    pullExporter.Collect = this.Collect;
                }
                else
                {
                    pullExporter.Collect = (timeoutMilliseconds) =>
                    {
                        using (PullMetricScope.Begin())
                        {
                            return(this.Collect(timeoutMilliseconds));
                        }
                    };
                }
            }

            this.exportCalledMessage    = $"{nameof(BaseExportingMetricReader)} calling {this.Exporter}.{nameof(this.Exporter.Export)} method.";
            this.exportSucceededMessage = $"{this.Exporter}.{nameof(this.Exporter.Export)} succeeded.";
            this.exportFailedMessage    = $"{this.Exporter}.{nameof(this.Exporter.Export)} failed.";
        }
        public PeriodicExportingMetricReader(
            BaseExporter <Metric> exporter,
            int exportIntervalMilliseconds = DefaultExportIntervalMilliseconds,
            int exportTimeoutMilliseconds  = DefaultExportTimeoutMilliseconds)
            : base(exporter)
        {
            if (exportIntervalMilliseconds <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(exportIntervalMilliseconds), exportIntervalMilliseconds, "exportIntervalMilliseconds should be greater than zero.");
            }

            if (exportTimeoutMilliseconds < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(exportTimeoutMilliseconds), exportTimeoutMilliseconds, "exportTimeoutMilliseconds should be non-negative.");
            }

            if ((this.SupportedExportModes & ExportModes.Push) != ExportModes.Push)
            {
                throw new InvalidOperationException($"The '{nameof(exporter)}' does not support '{nameof(ExportModes)}.{nameof(ExportModes.Push)}'");
            }

            this.exportIntervalMilliseconds = exportIntervalMilliseconds;
            this.exportTimeoutMilliseconds  = exportTimeoutMilliseconds;

            this.exporterThread = new Thread(new ThreadStart(this.ExporterProc))
            {
                IsBackground = true,
                Name         = $"OpenTelemetry-{nameof(PeriodicExportingMetricReader)}-{exporter.GetType().Name}",
            };
            this.exporterThread.Start();
        }
        public PeriodicExportingMetricReader(
            BaseExporter <Metric> exporter,
            int exportIntervalMilliseconds = DefaultExportIntervalMilliseconds,
            int exportTimeoutMilliseconds  = DefaultExportTimeoutMilliseconds)
            : base(exporter)
        {
            Guard.ThrowIfOutOfRange(exportIntervalMilliseconds, nameof(exportIntervalMilliseconds), min: 1);
            Guard.ThrowIfOutOfRange(exportTimeoutMilliseconds, nameof(exportTimeoutMilliseconds), min: 0);

            if ((this.SupportedExportModes & ExportModes.Push) != ExportModes.Push)
            {
                throw new InvalidOperationException($"The '{nameof(exporter)}' does not support '{nameof(ExportModes)}.{nameof(ExportModes.Push)}'");
            }

            this.exportIntervalMilliseconds = exportIntervalMilliseconds;
            this.exportTimeoutMilliseconds  = exportTimeoutMilliseconds;

            this.exporterThread = new Thread(new ThreadStart(this.ExporterProc))
            {
                IsBackground = true,
                Name         = $"OpenTelemetry-{nameof(PeriodicExportingMetricReader)}-{exporter.GetType().Name}",
            };
            this.exporterThread.Start();
        }
예제 #6
0
 void HandleExporter(MapDataInfo aMapDataInfo, BaseExporter aBaseExporter)
 {
     if (aBaseExporter is GroundExporter)
     {
         GroundExporter typedExporter = (GroundExporter)aBaseExporter;
         aMapDataInfo.m_GroundDataInfo.Add(typedExporter.ToGroundDataInfo());
     }
     else if (aBaseExporter is CameraLimitExporter)
     {
         CameraLimitExporter typedExporter = (CameraLimitExporter)aBaseExporter;
         aMapDataInfo.m_CameraLimitDataInfo.Add(typedExporter.ToCameraLimitDataInfo());
     }
     else if (aBaseExporter is ColliderExporter)
     {
         ColliderExporter typedExporter = (ColliderExporter)aBaseExporter;
         aMapDataInfo.m_ColliderDataInfo.Add(typedExporter.ToColliderDataInfo());
     }
     else if (aBaseExporter is SpawnPointExporter)
     {
         SpawnPointExporter typedExporter = (SpawnPointExporter)aBaseExporter;
         aMapDataInfo.m_SpawnPointDataInfo.Add(typedExporter.ToSpawnPointDataInfo());
     }
     else if (aBaseExporter is TeleportExporter)
     {
         TeleportExporter typedExporter = (TeleportExporter)aBaseExporter;
         aMapDataInfo.m_TeleportDataInfo.Add(typedExporter.ToTeleportDataInfo());
     }
     else
     {
         Debug.LogError("UnHandled Type of Exporter :: Name =" + aBaseExporter.name + " :: TypeOf =" + aBaseExporter.GetType());
     }
 }