Skip to main content
Version: v2

Adding Labels

Global Labels#

Subscription Service can have global labels in defaultSubscriberOptions, these will be merged with local subscriber level labels.

Env Var#

We also support GOOGLE_CLOUD_LABELS env var which can be a stringified JSON. These work as the default labels added to each subscription. Example:

# .env file
GOOGLE_CLOUD_LABELS='{"service": "hfc-pubsub", "env": "prod"}'

Subscriber Specific Labels#

Each subscriber can also add it's own labels, these overwrite the above mentioned Global Labels.

const TestSubscription: SubscriberObject<Payload> = {
topicName: 'test-topic',
subscriptionName: 'test-topic.example.subscription',
description: 'Just a test subscription',
options: {
labels: {
tribe: 'GFS',
service: 'pubsub',
},
},
async handleMessage(message): Promise<void> {
const payload = message.toJSON();
console.log(payload);
message.ack();
},
};