//-----------------------------------------------------------------------------
//
// 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 Amazon.Runtime.Internal.Util;
#if NETFRAMEWORK
using System.Net.Http;
#else
using Microsoft.AspNetCore.Http;
#endif
namespace Amazon.XRay.Recorder.Core.Strategies
{
///
/// Use a fixed name as segment name.
///
///
[CLSCompliant(false)]
public class FixedSegmentNamingStrategy : SegmentNamingStrategy
{
private static readonly Logger _logger = Logger.GetLogger(typeof(FixedSegmentNamingStrategy));
///
/// Initializes a new instance of the class.
///
/// Name of the fixed.
/// fixedName is null.
public FixedSegmentNamingStrategy(string fixedName)
{
if (string.IsNullOrEmpty(fixedName))
{
throw new ArgumentException("FixedName cannot be null or empty.", nameof(fixedName));
}
this.FixedName = fixedName;
string overrideName = GetSegmentNameFromEnvironmentVariable();
if (!string.IsNullOrEmpty(overrideName))
{
_logger.DebugFormat("{0} is set, overriding segment name to: {1}.", SegmentNamingStrategy.EnvironmentVariableSegmentName, overrideName);
this.FixedName = overrideName;
}
}
///
/// Gets or sets the name of the fixed.
///
public string FixedName { get; set; }
#if NETFRAMEWORK
///
/// Gets the name of the segment.
///
/// The request.
///
/// The segment name
///
public override string GetSegmentName(HttpRequestMessage httpRequest)
{
return FixedName;
}
///
/// Gets the name of the segment.
///
/// The HTTP request.
///
/// The segment name.
///
public override string GetSegmentName(System.Web.HttpRequest httpRequest)
{
return FixedName;
}
#else
///
/// Gets the name of the segment.
///
/// The HTTP request.
///
/// The segment name.
///
[CLSCompliant(false)]
public override string GetSegmentName(HttpRequest httpRequest)
{
return FixedName;
}
#endif
}
}