//-----------------------------------------------------------------------------
//
// 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.Runtime.ExceptionServices;
using Amazon.Runtime.Internal.Util;
using Amazon.XRay.Recorder.Core.Exceptions;
using Amazon.XRay.Recorder.Core.Internal.Entities;
using Amazon.XRay.Recorder.Core.Strategies;
namespace Amazon.XRay.Recorder.Core.Internal.Context
{
public abstract class TraceContextImpl : ITraceContext
{
private static readonly Logger _logger = Logger.GetLogger(typeof(TraceContextImpl));
///
/// Get entity (segment/subsegment) from the trace context.
///
/// The segment get from context
/// Thrown when the entity is not available to get.
public abstract Entity GetEntity();
///
/// Set the specified entity (segment/subsegment) into trace context.
///
/// The segment to be set
/// Thrown when the entity is not available to set
public abstract void SetEntity(Entity entity);
///
/// Clear entity from trace context for cleanup.
///
public abstract void ClearEntity();
///
/// Checks whether enity is present in trace context.
///
/// True if entity is present incontext container else false.
public abstract Boolean IsEntityPresent();
///
/// If the entity is missing from the context, the behavior is defined using
///
/// instance
/// Instance of
/// String message
public void HandleEntityMissing(IAWSXRayRecorder recorder, Exception e, string message)
{
_logger.Error(e, message);
if (recorder.ContextMissingStrategy == ContextMissingStrategy.LOG_ERROR)
{
_logger.DebugFormat("The ContextMissingStrategy is set to be LOG_ERROR. EntityNotAvailableException exception is suppressed.");
}
else
{
ExceptionDispatchInfo.Capture(e).Throw();
}
}
}
}