Skip to content

Commit

Permalink
report unknown label values to error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Oct 21, 2024
1 parent 1b1c5fd commit 42006ef
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# self-labeler

A [Bluesky](https://bsky.social/)/[AT Protocol](https://atproto.com/)'s [labeler aka mod service](https://bsky.social/about/blog/4-13-2023-moderation) that emits custom [self-labels](https://atproto.com/specs/label#self-labels-in-records) (except [global labels](https://docs.bsky.app/docs/advanced-guides/moderation#global-label-values)) that already exist inside records.
[bsky.app/profile/self-labeler.snarfed.org](https://bsky.app/profile/self-labeler.snarfed.org) (`did:plc:4wgmwsq4t3tg55ffl3r7ocec`)

A [Bluesky](https://bsky.social/)/[AT Protocol](https://atproto.com/) [labeler aka mod service](https://bsky.social/about/blog/4-13-2023-moderation) that emits custom [self-labels](https://atproto.com/specs/label#self-labels-in-records) (except [global labels](https://docs.bsky.app/docs/advanced-guides/moderation#global-label-values)) that already exist inside records.

Apart from the [global labels](https://docs.bsky.app/docs/advanced-guides/moderation#global-label-values) built into [bsky.app](https://bsky.app/), other custom self-labels are often not displayed or handled by clients. This surfaces those labels and makes them visible.

[Background discussion.](https://github.com/bluesky-social/atproto/discussions/2885)

License: This project is placed in the public domain. You may also use it under the [CC0 License](https://creativecommons.org/publicdomain/zero/1.0/).


## Setup

Expand Down Expand Up @@ -44,3 +48,8 @@ Apart from the [global labels](https://docs.bsky.app/docs/advanced-guides/modera
encryption_algorithm=serialization.NoEncryption(),
))
```
### Declaration record
The [labeler declaration record](https://docs.bsky.app/docs/advanced-guides/moderation#labeler-declarations) is `at://did:plc:4wgmwsq4t3tg55ffl3r7ocec/app.bsky.labeler.service/self'. To add a new label value definition to it, run `npx @skyware/labeler add`. [Docs.](https://skyware.js.org/guides/labeler/introduction/getting-started/)
14 changes: 13 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import arroba.util
from cryptography.hazmat.primitives import serialization
from flask import Flask
from google.cloud import error_reporting
import google.cloud.logging
import lexrpc.flask_server
import lexrpc.server
import simple_websocket
Expand All @@ -36,8 +38,17 @@
'sexual',
]

KNOWN_LABELS = [
'bridged-from-bridgy-fed-activitypub',
'bridged-from-bridgy-fed-web',
]

logger = logging.getLogger(__name__)
logging.basicConfig()
logging_client = google.cloud.logging.Client()
logging_client.setup_logging(log_level=logging.DEBUG)

error_reporting_client = error_reporting.Client()

logger.info('Loading #atproto_label private key from privkey.atproto_label.pem')
with open('privkey.atproto_label.pem', 'rb') as f:
Expand Down Expand Up @@ -83,6 +94,8 @@ def jetstream():
labels = []
uri = f'at://{msg["did"]}/{commit["collection"]}/{commit["rkey"]}'
for val in values:
if val not in KNOWN_LABELS:
error_reporting_client.report(f'new label! {val} {uri} {cid}')
label = {
'ver': 1,
'src': msg['did'],
Expand Down Expand Up @@ -123,7 +136,6 @@ def subscribe_labels(cursor=None):


# start jetstream consumer
# if LOCAL_SERVER or not DEBUG:
assert 'jetstream' not in [t.name for t in threading.enumerate()]
Thread(target=jetstream, name='jetstream').start()

Expand Down
2 changes: 1 addition & 1 deletion app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runtime_config:

resources:
cpu: 1
memory_gb: 1.6
memory_gb: 3.6

# can't be internal because Bluesky relay(s) need to be able to connect to us
# over websocket for subscribeRepos
Expand Down
27 changes: 25 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,48 @@ charset-normalizer==3.4.0
cryptography==43.0.3
dag-cbor==0.3.3
dag-json==0.3
deprecated==1.2.14
dnspython==2.7.0
Flask==3.0.3
flask-sock==0.7.0
Flask==3.0.3
google-api-core==2.21.0
google-auth==2.35.0
google-cloud-appengine-logging==1.4.5
google-cloud-audit-log==0.3.0
google-cloud-core==2.4.1
google-cloud-error-reporting==1.11.1
google-cloud-error-reporting==1.11.1
google-cloud-logging==3.11.3
google-cloud-logging==3.11.3
googleapis-common-protos==1.65.0
grapheme==0.6.0
grpc-google-iam-v1==0.13.1
grpcio-status==1.67.0
grpcio==1.67.0
h11==0.14.0
idna==3.10
importlib-metadata==8.4.0
iterators==0.2.0
Jinja2==3.1.4
lexrpc==1.0
libipld==1.2.3
MarkupSafe==3.0.2
multiformats==0.3.1.post4
multiformats-config==0.3.1
multiformats==0.3.1.post4
opentelemetry-api==1.27.0
proto-plus==1.24.0
protobuf==5.28.2
pyasn1-modules==0.4.1
pyasn1==0.6.1
pycparser==2.22
pyjwt==2.9.0
requests==2.32.3
rsa==4.9
simple-websocket==1.1.0
typing-extensions==4.12.2
typing-validation==1.2.11.post4
urllib3==2.2.3
Werkzeug==3.0.4
wrapt==1.16.0
wsproto==1.2.0
zipp==3.20.2
19 changes: 0 additions & 19 deletions test_app.py

This file was deleted.

0 comments on commit 42006ef

Please sign in to comment.