public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction) { var redisCommandWithArgumentsAsBytes = instrumentedMethodCall.MethodCall.MethodArguments.ExtractNotNullAs <byte[][]>(0); var redisCommand = redisCommandWithArgumentsAsBytes[0]; if (redisCommand == null) { return(Delegates.NoOp); } var operation = GetRedisCommand(redisCommand); var contextObject = instrumentedMethodCall.MethodCall.InvocationTarget; if (contextObject == null) { throw new NullReferenceException(nameof(contextObject)); } var host = TryGetPropertyName(PropertyHost, contextObject) ?? "unknown"; host = ConnectionStringParserHelper.NormalizeHostname(host); var portPathOrId = TryGetPropertyName(PropertyPortPathOrId, contextObject); var databaseName = TryGetPropertyName(PropertyDatabaseName, contextObject); var connectionInfo = new ConnectionInfo(host, portPathOrId, databaseName); var segment = transaction.StartDatastoreSegment(instrumentedMethodCall.MethodCall, ParsedSqlStatement.FromOperation(DatastoreVendor.Redis, operation), connectionInfo); return(Delegates.GetDelegateFor(segment)); }
public static ConnectionInfo GetConnectionInfoFromCursor(object asyncCursor, object collectionNamespace) { string host = null; string port = null; var channelSource = GetChannelSourceFieldFromGeneric(asyncCursor); var server = GetServerFromFromInterface(channelSource); EndPoint endpoint = GetEndPoint(server); var dnsEndpoint = endpoint as DnsEndPoint; var ipEndpoint = endpoint as IPEndPoint; if (dnsEndpoint != null) { port = dnsEndpoint.Port.ToString(); host = ConnectionStringParserHelper.NormalizeHostname(dnsEndpoint.Host); } if (ipEndpoint != null) { port = ipEndpoint.Port.ToString(); host = ConnectionStringParserHelper.NormalizeHostname(ipEndpoint.Address.ToString()); } var databaseName = GetDatabaseNameFromCollectionNamespace(collectionNamespace); return(new ConnectionInfo(host, port, databaseName)); }
public static ConnectionInfo GetConnectionInfoFromDatabase(object database) { var databaseName = GetDatabaseNameFromDatabase(database); var servers = GetServersFromDatabase(database); string port = null; string host = null; if (servers.Count == 1) { GetHostAndPortFromServer(servers[0], out var rawHost, out var rawPort); port = rawPort.ToString(); host = ConnectionStringParserHelper.NormalizeHostname(rawHost); } return(new ConnectionInfo(host, port, databaseName)); }
public static ConnectionInfo GetConnectionInfoFromConnectionMultiplexer(MethodCall methodCall, string assemblyName) { var connectionMultiplexer = methodCall.InvocationTarget; var rawConfig = GetRawConfigAccessor(assemblyName)(connectionMultiplexer); var endpoints = GetEndPointsAccessor(assemblyName)(rawConfig); if (endpoints == null || endpoints.Count <= 0) { return(null); } var endpoint = endpoints[0]; var dnsEndpoint = endpoint as DnsEndPoint; var ipEndpoint = endpoint as IPEndPoint; string port = null; string host = null; if (dnsEndpoint != null) { port = dnsEndpoint.Port.ToString(); host = ConnectionStringParserHelper.NormalizeHostname(dnsEndpoint.Host); } if (ipEndpoint != null) { port = ipEndpoint.Port.ToString(); host = ConnectionStringParserHelper.NormalizeHostname(ipEndpoint.Address.ToString()); } if (host == null) { return(null); } return(new ConnectionInfo(host, port, null)); }