public void ConnectionStringParser_DifferentConnectionStrings_NotMatched() { var connectionString1 = @"Server=win-database.pdx.vm.datanerd.us\SQLEXPRESS;Database=NewRelic;"; var connectionString2 = @"Server=win-database.pdx.vm.datanerd.us,1433\SQLEXPRESS;Database=NewRelic;"; var connectionInfo1 = ConnectionInfoParser.FromConnectionString(DatastoreVendor.MSSQL, connectionString1); var connectionInfo2 = ConnectionInfoParser.FromConnectionString(DatastoreVendor.MSSQL, connectionString2); Assert.AreNotSame(connectionInfo1, connectionInfo2); }
public void TestConnectionStringParsing(DatastoreVendor vendor, string expectedHost, string expectedPathPortOrId, string expectedDatabaseName, string expectedInstanceName, string connectionString) { if (expectedHost == "hostname_of_localhost") { expectedHost = Dns.GetHostName(); } var connectionInfo = ConnectionInfoParser.FromConnectionString(vendor, connectionString); Assert.True(connectionInfo.Host == expectedHost); Assert.True(connectionInfo.PortPathOrId == expectedPathPortOrId); Assert.True(connectionInfo.DatabaseName == expectedDatabaseName); Assert.True(connectionInfo.InstanceName == expectedInstanceName); }
public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall instrumentedMethodCall, IAgent agent, ITransaction transaction) { //This only happens if we are in an async context. Regardless if we are adding the after delegate as a contination. if (instrumentedMethodCall.IsAsync) { transaction.AttachToAsync(); } var sqlCommand = (IDbCommand)instrumentedMethodCall.MethodCall.InvocationTarget; if (sqlCommand == null) { return(Delegates.NoOp); } var sql = sqlCommand.CommandText ?? string.Empty; var vendor = SqlWrapperHelper.GetVendorName(sqlCommand); object GetConnectionInfo() => ConnectionInfoParser.FromConnectionString(vendor, sqlCommand.Connection.ConnectionString); var connectionInfo = (ConnectionInfo)transaction.GetOrSetValueFromCache(sqlCommand.Connection.ConnectionString, GetConnectionInfo); var parsedStatement = transaction.GetParsedDatabaseStatement(vendor, sqlCommand.CommandType, sql); var queryParameters = SqlWrapperHelper.GetQueryParameters(sqlCommand, agent); var segment = transaction.StartDatastoreSegment(instrumentedMethodCall.MethodCall, parsedStatement, connectionInfo, sql, queryParameters, isLeaf: true); switch (vendor) { case DatastoreVendor.MSSQL: agent.EnableExplainPlans(segment, () => SqlServerExplainPlanActions.AllocateResources(sqlCommand), SqlServerExplainPlanActions.GenerateExplainPlan, null); break; case DatastoreVendor.MySQL: if (parsedStatement != null) { agent.EnableExplainPlans(segment, () => MySqlExplainPlanActions.AllocateResources(sqlCommand), MySqlExplainPlanActions.GenerateExplainPlan, () => MySqlExplainPlanActions.ShouldGenerateExplainPlan(sql, parsedStatement)); } break; } return(ExecuteAsAsync ? Delegates.GetAsyncDelegateFor <Task>(agent, segment) : Delegates.GetDelegateFor(segment)); }