private static AttributeFilterNode CreateAttributeNode(string key, AttributeDestinations destinations, bool include)
        {
            var includes = include ? destinations : AttributeDestinations.None;
            var excludes = include ? AttributeDestinations.None : destinations;

            return(new AttributeFilterNode(key, includes, excludes));
        }
 private static string GetAttributeClusionKey(string name, AttributeDestinations defaultDestinations, AttributeDestinations destination)
 {
     // Enum is cast to byte to avoid enum.ToString which does reflection
     // The cache key includes both the intended destinations of the attribute (attribute.DefaultDestinations)
     // and the destination being tested.  This is because some attributes have the same name (like timestamp)
     // but different destinations.  Without this cache key, the wrong value will be selected.
     return(name + (((byte)destination << 8) + (byte)defaultDestinations).ToString());
 }
 protected AttributeValueCollectionBase(params AttributeDestinations[] targetModelTypes)
 {
     TargetModelTypes = targetModelTypes;
     foreach (var targetModelType in targetModelTypes)
     {
         TargetModelTypesAsFlags |= targetModelType;
     }
 }
        protected EventWireModel(AttributeDestinations targetObject, IAttributeValueCollection attribValues, bool isSynthetics, float priority)
        {
            _targetObject   = targetObject;
            AttributeValues = new AttributeValueCollection(attribValues, _targetObject);
            Priority        = priority;
            IsSynthetics    = isSynthetics;

            AttributeValues.MakeImmutable();
        }
        private Clude CheckForImplicitClusion(string name, AttributeDestinations defaultDestinations, AttributeDestinations destination)
        {
            if ((defaultDestinations & destination) != destination)
            {
                return(Clude.Exclude);
            }

            return(_implicitAttributeTrie.GetClusion(name, destination));
        }
Пример #6
0
        public AttributeDefinition(string name, AttributeClassification classification, Dictionary <AttributeDestinations, bool> availability)
        {
            Name           = name;
            Classification = classification;
            _availability  = availability;

            foreach (var k in availability.Where(x => x.Value))
            {
                AttributeDestinations |= k.Key;
            }
        }
Пример #7
0
 public AttributeFilterNode(string key, AttributeDestinations includes, AttributeDestinations excludes)
 {
     if (key.EndsWith("*"))
     {
         Wildcard = true;
         Key      = key.Substring(0, key.Length - 1);
     }
     else
     {
         Key = key;
     }
     DestinationIncludes = includes;
     DestinationExcludes = excludes;
 }
        public bool CheckOrAddAttributeClusionCache(string name, AttributeDestinations defaultDestinations, AttributeDestinations destination)
        {
            var cacheKey = GetAttributeClusionKey(name, defaultDestinations, destination);

            if (!_cachedClusions.TryGetValue(cacheKey, out var result))
            {
                result = !ShouldExcludeAttribute(name, defaultDestinations, destination);

                if (_cachedClusions.Count <= MaxCacheSize)
                {
                    _cachedClusions.TryAdd(cacheKey, result);
                }
            }

            return(result);
        }
        public bool ShouldExcludeAttribute(string name, AttributeDestinations defaultDestinations, AttributeDestinations destination)
        {
            var explicitClusion = CheckForExplicitClusion(name, destination);

            if (explicitClusion != Clude.Unknown)
            {
                return(KnownCludeToBoolean(explicitClusion));
            }

            var implicitClusion = CheckForImplicitClusion(name, defaultDestinations, destination);

            if (implicitClusion != Clude.Unknown)
            {
                return(KnownCludeToBoolean(implicitClusion));
            }

            return(false);
        }
Пример #10
0
        public static AttributeDefinitionBuilder <object, object> CreateCustomAttribute(string name, AttributeDestinations destination)
        {
            var builder = Create <object, object>(name, AttributeClassification.UserAttributes);

            builder.AppliesTo(destination, true);

            builder.WithConvert((input) =>
            {
                if (input == null)
                {
                    return(null);
                }

                if (input is TimeSpan)
                {
                    return(((TimeSpan)input).TotalSeconds);
                }
                else if (input is DateTimeOffset)
                {
                    return(((DateTimeOffset)input).ToString("o"));
                }

                switch (Type.GetTypeCode(input.GetType()))
                {
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                case TypeCode.Int16:
                case TypeCode.Int32:
                    return(Convert.ToInt64(input));

                case TypeCode.Decimal:
                case TypeCode.Single:
                    return(Convert.ToDouble(input));

                case TypeCode.Double:
                case TypeCode.Int64:
                case TypeCode.Boolean:
                case TypeCode.String:
                    return(input);

                case TypeCode.DateTime:
                    return(((DateTime)input).ToString("o"));
                }

                return(input.ToString());
            });

            return(builder);
        }
Пример #11
0
        public static Clude GetClusion(this TrieNode <AttributeFilterNode> nodeBuilder, string name, AttributeDestinations destination)
        {
            var childClusion = nodeBuilder.GetClusionFromChildren(name, destination);

            if (childClusion != Clude.Unknown)
            {
                return(childClusion);
            }

            var exclude = (nodeBuilder.Data.DestinationExcludes & destination) == destination;

            if (exclude)
            {
                return(Clude.Exclude);
            }

            var include = (nodeBuilder.Data.DestinationIncludes & destination) == destination;

            if (include)
            {
                return(Clude.Include);
            }

            return(Clude.Unknown);
        }
Пример #12
0
        private static Clude GetChildClusion(this TrieNode <AttributeFilterNode> child, string name, AttributeDestinations destination)
        {
            if (child == null)
            {
                return(Clude.Unknown);
            }

            return(child.GetClusion(name, destination));
        }
        public bool ShouldFilterAttribute(AttributeDestinations targetObjectType)
        {
            if (!_settings.AttributesEnabled)
            {
                return(true);
            }

            switch (targetObjectType)
            {
            case AttributeDestinations.SpanEvent:
                if (!_settings.SpanEventsEnabled)
                {
                    return(true);
                }
                break;

            case AttributeDestinations.ErrorTrace:
                if (!_settings.ErrorTraceEnabled)
                {
                    return(true);
                }
                break;

            case AttributeDestinations.JavaScriptAgent:
                if (!_settings.JavaScriptAgentEnabled)
                {
                    return(true);
                }
                break;

            case AttributeDestinations.TransactionEvent:
                if (!_settings.TransactionEventEnabled)
                {
                    return(true);
                }
                break;

            case AttributeDestinations.TransactionTrace:
                if (!_settings.TransactionTraceEnabled)
                {
                    return(true);
                }
                break;

            case AttributeDestinations.ErrorEvent:
                if (!_settings.ErrorEventsEnabled)
                {
                    return(true);
                }
                break;

            case AttributeDestinations.SqlTrace:
                break;

            case AttributeDestinations.CustomEvent:
                if (!_settings.CustomEventsEnabled)
                {
                    return(true);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("destination", "Unexpected destination: " + targetObjectType);
            }

            return(false);
        }
Пример #14
0
        public static Dictionary <string, object> ToDictionary(this IAttributeValueCollection attribValueCollection, AttributeDestinations targetObject, params AttributeClassification[] classifications)
        {
            var filteredAttribValues = new AttributeValueCollection(attribValueCollection, targetObject);

            return(ToDictionary(filteredAttribValues, classifications));
        }
 private static IEnumerable <AttributeFilterNode> CreateAttributeNodes(IEnumerable <string> keys, AttributeDestinations destinations, bool include)
 {
     return(keys
            .Where(key => key != null)
            .Select(key => CreateAttributeNode(key, destinations, include)));
 }
Пример #16
0
        private static Clude GetClusionFromChildren(this TrieNode <AttributeFilterNode> nodeBuilder, string name, AttributeDestinations destination)
        {
            var child        = nodeBuilder.ApplicableChild(name);
            var childClusion = child.GetChildClusion(name, destination);

            return(childClusion);
        }
 private Clude CheckForExplicitClusion(string name, AttributeDestinations destination)
 {
     return(_explicitAttributeTrie.GetClusion(name, destination));
 }