Skip to content

Commit fbc460b

Browse files
committed
Apply warm up runs plus hoist Attributes to inline
1 parent c924b19 commit fbc460b

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

observability-test/benchmark.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const lessComparator = (a, b) => {
2727
*/
2828
export async function runBenchmarks(runners: Function[], done: Function) {
2929
const nRuns = 10000;
30-
const benchmarkValues = {_totalRuns: nRuns};
30+
const nWarmups = Math.round(nRuns / 8);
31+
const benchmarkValues = {_totalRuns: nRuns, _warmRuns: nWarmups};
3132

3233
let k = 0;
3334
for (k = 0; k < runners.length; k++) {
@@ -38,7 +39,7 @@ export async function runBenchmarks(runners: Function[], done: Function) {
3839
let i = 0;
3940

4041
// Warm up runs to ensure stable behavior.
41-
for (i = 0; i < 8; i++) {
42+
for (i = 0; i < nWarmups; i++) {
4243
const value = await fn();
4344
}
4445

observability-test/comparisons.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async function setup(
124124
});
125125
}
126126

127-
describe('Benchmarking', () => {
127+
describe('Benchmarking Database', () => {
128128
if (!process.env.SPANNER_RUN_BENCHMARKS) {
129129
console.log(
130130
'Skipping micro-benchmarking because SPANNER_RUN_BENCHMARKS is not set'
@@ -289,7 +289,9 @@ describe('Benchmarking', () => {
289289
const untraced = await setItUp(false);
290290
const tracedWithOTELOn = await setItUp(true, true);
291291

292-
console.log(`Total Runs: ${traced['_totalRuns']}`);
292+
console.log(
293+
`Total Runs: ${traced['_totalRuns']}\nWarm up runs: ${traced['_warmRuns']}`
294+
);
293295
for (const tracedM in traced) {
294296
const tracedV = traced[tracedM];
295297
if (typeof tracedV !== 'object') {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"samples-test-with-archived": "cd samples/ && npm link ../ && npm test-with-archived && cd ../",
3434
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
3535
"system-test": "mocha build/system-test --timeout 1600000",
36-
"observability-test": "mocha build/observability-test --timeout 1600000 -g 'Benchmarking'",
36+
"observability-test": "mocha build/observability-test --timeout 1600000",
3737
"cleanup": "mocha scripts/cleanup.js --timeout 30000",
3838
"test": "mocha build/test build/test/common build/observability-test",
3939
"ycsb": "node ./benchmark/ycsb.js run -P ./benchmark/workloada -p table=usertable -p cloudspanner.instance=ycsb-instance -p operationcount=100 -p cloudspanner.database=ycsb",

src/instrument.ts

+22-24
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '@opentelemetry/semantic-conventions';
2525

2626
import {
27+
Attributes,
2728
Span,
2829
SpanStatusCode,
2930
context,
@@ -136,33 +137,30 @@ export function startTrace<T>(
136137
config = {} as traceConfig;
137138
}
138139

140+
const spanAttributes: Attributes = {
141+
SEMATTRS_DB_SYSTEM: 'spanner',
142+
ATTR_OTEL_SCOPE_NAME: TRACER_NAME,
143+
ATTR_OTEL_SCOPE_VERSION: TRACER_VERSION,
144+
SEMATTRS_DB_SQL_TABLE: config.tableName,
145+
SEMATTRS_DB_NAME: config.dbName,
146+
kind: SpanKind.CLIENT,
147+
};
148+
149+
const allowExtendedTracing = optedInPII || config.opts?.enableExtendedTracing;
150+
if (config.sql && allowExtendedTracing) {
151+
const sql = config.sql;
152+
if (typeof sql === 'string') {
153+
spanAttributes[SEMATTRS_DB_STATEMENT] = sql as string;
154+
} else {
155+
const stmt = sql as SQLStatement;
156+
spanAttributes[SEMATTRS_DB_STATEMENT] = stmt.sql;
157+
}
158+
}
159+
139160
return getTracer(config.opts?.tracerProvider).startActiveSpan(
140161
SPAN_NAMESPACE_PREFIX + '.' + spanNameSuffix,
141-
{kind: SpanKind.CLIENT},
162+
spanAttributes,
142163
span => {
143-
span.setAttribute(SEMATTRS_DB_SYSTEM, 'spanner');
144-
span.setAttribute(ATTR_OTEL_SCOPE_NAME, TRACER_NAME);
145-
span.setAttribute(ATTR_OTEL_SCOPE_VERSION, TRACER_VERSION);
146-
147-
if (config.tableName) {
148-
span.setAttribute(SEMATTRS_DB_SQL_TABLE, config.tableName);
149-
}
150-
if (config.dbName) {
151-
span.setAttribute(SEMATTRS_DB_NAME, config.dbName);
152-
}
153-
154-
const allowExtendedTracing =
155-
optedInPII || config.opts?.enableExtendedTracing;
156-
if (config.sql && allowExtendedTracing) {
157-
const sql = config.sql;
158-
if (typeof sql === 'string') {
159-
span.setAttribute(SEMATTRS_DB_STATEMENT, sql as string);
160-
} else {
161-
const stmt = sql as SQLStatement;
162-
span.setAttribute(SEMATTRS_DB_STATEMENT, stmt.sql);
163-
}
164-
}
165-
166164
// If at all the invoked function throws an exception,
167165
// record the exception and then end this span.
168166
try {

0 commit comments

Comments
 (0)