//-----------------------------------------------------------------------------
//
// Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//-----------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Amazon.XRay.Recorder.Core.Sampling;
using Amazon.XRay.Recorder.Core.Strategies;
using System.Threading.Tasks;
using Amazon.XRay.Recorder.Core.Exceptions;
using Amazon.XRay.Recorder.Core.Internal.Context;
using Amazon.XRay.Recorder.Core.Internal.Emitters;
namespace Amazon.XRay.Recorder.Core
{
///
/// Interface to record tracing information for AWS X-Ray
///
public interface IAWSXRayRecorder : IDisposable
{
///
/// Gets or sets origin service
///
string Origin { get; set; }
///
/// Gets or sets the sampling strategy
///
ISamplingStrategy SamplingStrategy { get; set; }
///
/// Get or sets the streaming strategy
///
IStreamingStrategy StreamingStrategy { get; set; }
///
/// Gets or sets the context missing strategy.
///
ContextMissingStrategy ContextMissingStrategy { get; set; }
///
/// Gets the runtime context which is generated by plugins.
///
IDictionary RuntimeContext { get; }
///
/// Defines exception serialization stategy to process recorded exceptions.
///
ExceptionSerializationStrategy ExceptionSerializationStrategy { get; set; }
///
/// Instance of , used to store segment/subsegment.
///
ITraceContext TraceContext { get; set; }
///
/// Emitter used to send Traces.
///
ISegmentEmitter Emitter { get; set; }
///
/// Begin a tracing segment. A new tracing segment will be created and started.
///
/// The name of the segment
/// Trace id of the segment
/// Unique id of the upstream remote segment or subsegment where the downstream call originated from.
/// Instance of , contains sampling decision for the segment from upstream service. If not passed, sampling decision is made based on set with the recorder instance.
/// If not null, sets the start time for the segment else current time is set.
/// The argument has a null value.
void BeginSegment(string name, string traceId = null, string parentId = null, SamplingResponse samplingResponse = null, DateTime? timestamp = null);
///
/// End tracing of a given segment.
///
/// If not null, set as endtime for the current segment.
/// Entity is not available in trace context.
void EndSegment(DateTime? timestamp = null);
///
/// Start a subsegment with a given name and optional creation timestamp
///
/// Name of the subsegment
/// Sets the start time for the subsegment
void BeginSubsegment(string name, DateTime? timestamp = null);
///
/// Start a subsegment with a given name
/// This subsegment will not emit and its trace context will have Sampled=0
///
/// Name of the subsegment
void BeginSubsegmentWithoutSampling(string name);
///
/// End a subsegment
///
/// Sets the end time for the subsegment
void EndSubsegment(DateTime? timestamp = null);
///
/// Set namespace to current segment
///
/// The value of the namespace
void SetNamespace(string value);
///
/// Adds the specified key and value as annotation to current segment
///
/// The key of the annotation to add
/// The value of the annotation to add
void AddAnnotation(string key, object value);
///
/// Mark the current segment as fault.
///
void MarkFault();
///
/// Mark the current segment as error.
///
void MarkError();
///
/// Add the exception to current segment
///
/// The exception to be added.
void AddException(Exception ex);
///
/// Trace a given method with return value.
///
/// The type of the return value of the method that this delegate encapsulates
/// The name of the trace subsegment for the method
/// The method to be traced
/// The return value of the given method
TResult TraceMethod(string name, Func method);
///
/// Trace a given method returns void.
///
/// The name of the trace subsegment for the method
/// The method to be traced
void TraceMethod(string name, Action method);
///
/// Trace a given asynchronous function with return value. A subsegment will be created for this method.
/// Any exception thrown by the method will be captured.
///
/// The type of the return value of the method that this delegate encapsulates
/// The name of the trace subsegment for the method
/// The method to be traced
/// The return value of the given method
Task TraceMethodAsync(string name, Func> method);
///
/// Trace a given asynchronous method that returns no value. A subsegment will be created for this method.
/// Any exception thrown by the method will be captured.
///
/// The name of the trace subsegment for the method
/// The method to be traced
Task TraceMethodAsync(string name, Func method);
///
/// Adds the specified key and value as http information to current segment
///
/// The key of the http information to add
/// The value of the http information to add
void AddHttpInformation(string key, object value);
///
/// Mark the current segment as being throttled.
///
void MarkThrottle();
///
/// Add a precursor id.
///
/// The precursor id to be added.
void AddPrecursorId(string precursorId);
///
/// Add the specified key and value as SQL information to current segment
///
/// The key of the SQL information
/// The value of the SQL information
void AddSqlInformation(string key, string value);
///
/// Adds the specified key and value to metadata under default namespace.
///
/// The key.
/// The value.
void AddMetadata(string key, object value);
///
/// Adds the specified key and value to metadata with given namespace.
///
/// The namespace.
/// The key.
/// The value.
void AddMetadata(string nameSpace, string key, object value);
///
/// Sets the daemon address.
/// The daemon address should be in format "IPAddress:Port", i.e. "127.0.0.1:2000".
/// If environment variable is set to specific daemon address, the call to this method
/// will be ignored.
///
/// The daemon address.
void SetDaemonAddress(string daemonAddress);
}
}