func BeginDatastoreSegment(
	txnID int64,
	parentID int64,
	table string,
	operation string,
	sql string,
	rollupName string,
) int64 {
	ctable := C.CString(table)
	defer C.free(unsafe.Pointer(ctable))
	coperation := C.CString(operation)
	defer C.free(unsafe.Pointer(coperation))
	csql := C.CString(sql)
	defer C.free(unsafe.Pointer(csql))
	crollupName := C.CString(rollupName)
	defer C.free(unsafe.Pointer(crollupName))
	id := C.newrelic_segment_datastore_begin(
		C.long(txnID),
		C.long(parentID),
		ctable,
		coperation,
		csql,
		crollupName,
		(*[0]byte)(C.newrelic_basic_literal_replacement_obfuscator),
	)
	return int64(id)
}
func StartDatastoreStatement(tId TTransactionId, sId SegmentId, table string, operation string) SegmentId {
	if operation != NR_DATASTORE_OPERATION_SELECT &&
		operation != NR_DATASTORE_OPERATION_INSERT &&
		operation != NR_DATASTORE_OPERATION_UPDATE &&
		operation != NR_DATASTORE_OPERATION_DELETE {
		return SegmentId(0)
	}

	cTable := C.CString(table)
	defer C.free(unsafe.Pointer(cTable))

	cOperation := C.CString(operation)
	defer C.free(unsafe.Pointer(cOperation))

	cId := C.long(tId)
	cSeg := C.long(sId)

	result := C.newrelic_segment_datastore_begin(cId, cSeg, cTable, cOperation)
	return SegmentId(result)
}
Beispiel #3
0
/*
 * Identify the beginning of a segment that performs a database operation.
 *
 *
 * SQL Obfuscation
 * ===============
 * If you supply the sql_obfuscator parameter with NULL, the supplied SQL string
 * will go through our basic literal replacement obfuscator that strips the SQL
 * string literals (values between single or double quotes) and numeric
 * sequences, replacing them with the ? character. For example:
 *
 * This SQL:
 * 		SELECT * FROM table WHERE ssn=‘000-00-0000’
 *
 * obfuscates to:
 * 		SELECT * FROM table WHERE ssn=?
 *
 * Because our default obfuscator just replaces literals, there could be
 * cases that it does not handle well. For instance, it will not strip out
 * comments from your SQL string, it will not handle certain database-specific
 * language features, and it could fail for other complex cases.
 *
 * If this level of obfuscation is not sufficient, you can supply your own
 * custom obfuscator via the sql_obfuscator parameter.
 *
 * SQL Trace Rollup
 * ================
 * The agent aggregates similar SQL statements together using the supplied
 * sql_trace_rollup_name.
 *
 * To make the most out of this feature, you should either (1) supply the
 * sql_trace_rollup_name parameter with a name that describes what the SQL is
 * doing, such as "get_user_account" or (2) pass it NULL, in which case
 * it will use the sql obfuscator to generate a name.
 *
 * @param transaction_id  id of transaction
 * @param parent_segment_id  id of parent segment
 * @param table  name of the database table
 * @param operation  name of the sql operation
 * @param sql  the sql string
 * @param sql_trace_rollup_name  the rollup name for the sql trace
 * @param sql_obfuscator  a function pointer that takes sql and obfuscates it
 * @return  segment id on success, else negative warning code or error code
 */
func SegmentDatastoreBegin(id, parent int64, table, operation, sql, sqlTraceRollupName string) (int64, error) {
	ctable := C.CString(table)
	defer C.free(unsafe.Pointer(ctable))

	coperation := C.CString(operation)
	defer C.free(unsafe.Pointer(coperation))

	csql := C.CString(sql)
	defer C.free(unsafe.Pointer(csql))

	csqlTraceRollupName := C.CString(sqlTraceRollupName)
	defer C.free(unsafe.Pointer(csqlTraceRollupName))

	return errNoLong(C.newrelic_segment_datastore_begin(
		C.long(id),
		C.long(parent),
		ctable,
		coperation,
		csql,
		csqlTraceRollupName,
		(*[0]byte)(C.newrelic_basic_literal_replacement_obfuscator),
	))
}