Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable tracing via OpenTelemetry #2219

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Unit_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions dev/conformance/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {DocumentData} from '@google-cloud/firestore';

import * as duplexify from 'duplexify';

import {it, xit, describe} from 'mocha';
Expand Down Expand Up @@ -47,6 +45,7 @@
} from '../test/util/helpers';

import api = proto.google.firestore.v1;
import {FirebaseFirestore} from '../../types/firestore';

// TODO(mrschmidt): Create Protobuf .d.ts file for the conformance proto
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -183,7 +182,7 @@
args.push(
DocumentSnapshot.fromObject(
docRef(cursor.docSnapshot.path),
convertInput.argument(cursor.docSnapshot.jsonData) as DocumentData
convertInput.argument(cursor.docSnapshot.jsonData) as FirebaseFirestore.DocumentData

Check failure on line 185 in dev/conformance/runner.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `cursor.docSnapshot.jsonData` with `⏎············cursor.docSnapshot.jsonData⏎··········`
)
);
} else {
Expand Down Expand Up @@ -406,7 +405,7 @@
}
}
return docRef(setSpec.docRefPath).set(
convertInput.argument(spec.jsonData) as DocumentData,
convertInput.argument(spec.jsonData) as FirebaseFirestore.DocumentData,
setOption
);
});
Expand All @@ -416,7 +415,7 @@
const overrides = {commit: commitHandler(spec)};
return createInstance(overrides).then(() => {
return docRef(spec.docRefPath).create(
convertInput.argument(spec.jsonData) as DocumentData
convertInput.argument(spec.jsonData) as FirebaseFirestore.DocumentData
);
});
};
Expand Down
3 changes: 2 additions & 1 deletion dev/src/aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import {FieldPath} from './path';
import {google} from '../protos/firestore_v1_proto_api';
Expand Down
6 changes: 4 additions & 2 deletions dev/src/bulk-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as firestore from '@google-cloud/firestore';

import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as assert from 'assert';
import type {GoogleError} from 'google-gax';
Expand Down Expand Up @@ -47,7 +49,7 @@ import {logger} from './logger';
import {StatusCode} from './status-code';

// eslint-disable-next-line no-undef
import GrpcStatus = FirebaseFirestore.GrpcStatus;
import GrpcStatus = firestore.GrpcStatus;
import api = google.firestore.v1;
import {
ATTRIBUTE_KEY_DOC_COUNT,
Expand Down
4 changes: 3 additions & 1 deletion dev/src/collection-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as protos from '../protos/firestore_v1_proto_api';

import {QueryPartition} from './query-partition';
Expand Down
3 changes: 2 additions & 1 deletion dev/src/document-change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import {QueryDocumentSnapshot} from './document';

Expand Down
16 changes: 12 additions & 4 deletions dev/src/document-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import {DocumentSnapshot, DocumentSnapshotBuilder} from './document';
import {DocumentReference} from './reference/document-reference';
import {FieldPath} from './path';
Expand All @@ -22,10 +25,12 @@ import {google} from '../protos/firestore_v1_proto_api';
import {logger} from './logger';
import {Firestore} from './index';
import {Timestamp} from './timestamp';
import {DocumentData} from '@google-cloud/firestore';
import api = google.firestore.v1;

interface BatchGetResponse<AppModelType, DbModelType extends DocumentData> {
interface BatchGetResponse<
AppModelType,
DbModelType extends firestore.DocumentData,
> {
result: Array<DocumentSnapshot<AppModelType, DbModelType>>;
/**
* The transaction that was started as part of this request. Will only be if
Expand All @@ -41,7 +46,10 @@ interface BatchGetResponse<AppModelType, DbModelType extends DocumentData> {
* @private
* @internal
*/
export class DocumentReader<AppModelType, DbModelType extends DocumentData> {
export class DocumentReader<
AppModelType,
DbModelType extends firestore.DocumentData,
> {
private readonly outstandingDocuments = new Set<string>();
private readonly retrievedDocuments = new Map<string, DocumentSnapshot>();
private retrievedTransactionId?: Uint8Array;
Expand Down Expand Up @@ -166,7 +174,7 @@ export class DocumentReader<AppModelType, DbModelType extends DocumentData> {
this.retrievedTransactionId = response.transaction;
}

let snapshot: DocumentSnapshot<DocumentData> | undefined;
let snapshot: DocumentSnapshot<firestore.DocumentData> | undefined;
if (response.found) {
logger(
'DocumentReader.fetchDocuments',
Expand Down
3 changes: 2 additions & 1 deletion dev/src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as deepEqual from 'fast-deep-equal';

Expand Down
3 changes: 2 additions & 1 deletion dev/src/field-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as deepEqual from 'fast-deep-equal';

Expand Down
3 changes: 2 additions & 1 deletion dev/src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

/**
* A `Filter` represents a restriction on one or more field values and can
Expand Down
5 changes: 3 additions & 2 deletions dev/src/geo-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';

import {google} from '../protos/firestore_v1_proto_api';
import {Serializable} from './serializer';
import {validateNumber} from './validate';

import api = google.firestore.v1;

import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

/**
* An immutable object representing a geographic location in Firestore. The
* location is represented as a latitude/longitude pair.
Expand Down
7 changes: 3 additions & 4 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';

import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;
import type {CallOptions, ClientOptions} from 'google-gax';
import type * as googleGax from 'google-gax';
import type * as googleGaxFallback from 'google-gax/build/src/fallback';
Expand Down Expand Up @@ -792,8 +792,7 @@ export class Firestore implements firestore.Firestore {
}

private newTraceUtilInstance(settings: firestore.Settings): TraceUtil {
// Take the tracing option from the settings.
let createEnabledInstance = settings.openTelemetryOptions?.enableTracing;
let createEnabledInstance = true;

// The environment variable can override options to enable/disable telemetry collection.
if ('FIRESTORE_ENABLE_TRACING' in process.env) {
Expand Down
3 changes: 2 additions & 1 deletion dev/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import {google} from '../protos/firestore_v1_proto_api';

Expand Down
4 changes: 3 additions & 1 deletion dev/src/query-partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as protos from '../protos/firestore_v1_proto_api';

import {FieldOrder} from './reference/field-order';
Expand Down
4 changes: 3 additions & 1 deletion dev/src/query-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import {google} from '../protos/firestore_v1_proto_api';
import {Serializer} from './serializer';
import IPlanSummary = google.firestore.v1.IPlanSummary;
Expand Down
4 changes: 3 additions & 1 deletion dev/src/recursive-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as firestore from '@google-cloud/firestore';

import * as types from '../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as assert from 'assert';

Expand Down
3 changes: 2 additions & 1 deletion dev/src/reference/aggregate-query-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import * as deepEqual from 'fast-deep-equal';

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;
import {Timestamp} from '../timestamp';
import {AggregateQuery} from './aggregate-query';

Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/aggregate-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
import * as protos from '../../protos/firestore_v1_proto_api';
import api = protos.google.firestore.v1;

import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import * as assert from 'assert';
import * as deepEqual from 'fast-deep-equal';

import * as firestore from '@google-cloud/firestore';
import {Aggregate, AggregateSpec} from '../aggregate';
import {Timestamp} from '../timestamp';
import {mapToArray, requestTag, wrapError} from '../util';
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/collection-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import * as protos from '../../protos/firestore_v1_proto_api';
import api = protos.google.firestore.v1;

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {
QualifiedResourcePath,
ResourcePath,
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/document-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import * as protos from '../../protos/firestore_v1_proto_api';
import api = protos.google.firestore.v1;

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import Firestore, {DocumentSnapshot, WriteBatch, WriteResult} from '../index';
import {ResourcePath, validateResourcePath} from '../path';
import {defaultConverter} from '../types';
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {invalidArgumentMessage, validateEnumValue} from '../validate';
import {validateUserInput} from '../serializer';
import {DocumentReference} from './document-reference';
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import * as protos from '../../protos/firestore_v1_proto_api';
import api = protos.google.firestore.v1;
import * as deepEqual from 'fast-deep-equal';

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {ResourcePath} from '../path';
import {defaultConverter} from '../types';
import {FilterInternal} from './filter-internal';
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/query-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {QueryDocumentSnapshot} from '../document';
import {DocumentChange} from '../document-change';
import {Timestamp} from '../timestamp';
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/query-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {GoogleError} from 'google-gax';
import {Duplex, Transform} from 'stream';

Expand Down
5 changes: 4 additions & 1 deletion dev/src/reference/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

import * as protos from '../../protos/firestore_v1_proto_api';
import api = protos.google.firestore.v1;
import * as firestore from '@google-cloud/firestore';

import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {GoogleError} from 'google-gax';
import {Transform} from 'stream';

Expand Down
5 changes: 3 additions & 2 deletions dev/src/reference/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
import * as protos from '../../protos/firestore_v1_proto_api';
import api = protos.google.firestore.v1;

import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {Timestamp} from '../timestamp';
import {ExplainMetrics} from '../query-profile';
import {QueryDocumentSnapshot} from '../document';

import * as firestore from '@google-cloud/firestore';

export interface QueryStreamElement<
AppModelType = firestore.DocumentData,
DbModelType extends firestore.DocumentData = firestore.DocumentData,
Expand Down
3 changes: 2 additions & 1 deletion dev/src/reference/vector-query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

/**
* Specifies the behavior of the {@link VectorQuery} generated by a call to {@link Query.findNearest}.
Expand Down
4 changes: 3 additions & 1 deletion dev/src/reference/vector-query-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
* limitations under the License.
*/

import * as firestore from '@google-cloud/firestore';
import * as types from '../../../types/firestore';
import firestore = types.FirebaseFirestore;

import {QueryDocumentSnapshot} from '../document';
import {DocumentChange} from '../document-change';
import {Timestamp} from '../timestamp';
Expand Down
Loading
Loading